0

I am using this function to remove anything other than numbers, but it is giving me error, value.replace in not a function, Here's the function :

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

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

+1, I'd also like to add: Try value.toString().replace(/[^0-9.]+/g,''); to make the function a bit more robust and accept numbers and objects and such.
I am passing a number with comma, and i want to remove the comma, so that i can do the calculation with that number.
0
function filter_value(value) {
    return parseInt(value.toString().replace(/\D+/g,''), 10);
}

This will return integer value

1 Comment

It is not working, for example if i pass the digit 1,002, it makes it 1 & skip 002, Please help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.