开发者

Problem in removing special characters from a string through js

开发者 https://www.devze.com 2023-04-01 17:58 出处:网络
I am using this function to remove anything other than numbers, but it is giving me error, value.replace in not a f开发者_StackOverflow中文版unction, Here\'s the function :

I am using this function to remove anything other than numbers, but it is giving me error, value.replace in not a f开发者_StackOverflow中文版unction, Here's the function :

function filter_value(value)
{
    var filter = value.replace(/[^0-9.]+/g,''); 
    return filter;
}


If replace is not a function then value is not a string. Make sure you pass a string to the function.


function filter_value(value) {
    return parseInt(value.toString().replace(/\D+/g,''), 10);
}

This will return integer value

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号