How can you remove letters, symbols such as ∞§¶•ªºº«≥≤÷
but leaving plain numbers 0-9, I want to be able to not allow letters or certain symbols in an input fie
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.
Use /[^0-9.,]+/
if you want floats.
Simple:
var removedText = self.val().replace(/[^0-9]+/, '');
^ - means NOT
You can use \D
which means non digits.
var removedText = self.val().replace(/\D+/g, '');
jsFiddle.
You could also use the HTML5 number input.
<input type="number" name="digit" />
jsFiddle.
If you want to keep only numbers then use /[^0-9]+/
instead of /[^a-zA-Z]+/