How can I modify the following so that it keeps the character ‘.’?
This my regular expression:
a.replace(/[^\d]/g,'');
I am learning them, and I can see that it will keep the numbers from 0 to 9 only. Which is correct for my needs, however sometimes I need to pass a number such as 1.44 and this will just erase the ‘.’.
Thanks!
[^\d]is a character class that means anything except (^) digits (\d). You want it to remove anything except digits and periods, so just add the.to the character class: