开发者

Problem in removing special characters from a string through js

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜