How can you remove letters, symbols such as 8§¶•ªºº«==÷
but leaving plain numbers 0-9, I want to be able to not allow letters or certain symbols in an input field but to leave numbers only.
Demo.
If you put any symbols like ¡ € # ¢ 8 § ¶ • ª
or else, it still does not remove it from the input field. How do you remove symbols too? The \w
modifier does not work either.
This question is related to
javascript
regex
symbols
Try the following regex:
var removedText = self.val().replace(/[^0-9]/, '');
This will match every character that is not (^
) in the interval 0-9.
Demo.
If you want to keep only numbers then use /[^0-9]+/
instead of /[^a-zA-Z]+/
Use /[^0-9.,]+/
if you want floats.
Simple:
var removedText = self.val().replace(/[^0-9]+/, '');
^ - means NOT
Source: Stackoverflow.com