I'm using a regular expression in javascript that allows only numbers and two kinds of separators "," or "." This regular expression is the following:
/^[0-9]+([,.][0-9]+)?$/g
Now, it's mandatory that if a user tries to enter a character or something else besides a number with , or . separator to prevent him. To be more specific if a user types 123asv
I should display only the 123.
So i wrote this:
value.replace(/[0-9]+([,.][0-9]+)?$/g, '');
But this is not allowing enter number. This is reasonable because i replace every value that matches the above regex with space. How to edit it so as to achieve the desired functionality?