[英]Regex to remove letters, symbols except numbers
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 field but to leave numbers only.你怎么能删除字母,符号,如∞§¶•ªºº«≥≤÷
但留下普通数字0-9,我希望能够在输入字段中不允许字母或某些符号,而只留下数字。
If you put any symbols like ¡ € # ¢ ∞ § ¶ • ª
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. \w
修饰符也不起作用。
Use /[^0-9.,]+/
if you want floats.如果需要浮点数,请使用/[^0-9.,]+/
。
Simple:简单的:
var removedText = self.val().replace(/[^0-9]+/, '');
^ - means NOT ^ - 表示不
If you want to keep only numbers then use /[^0-9]+/
instead of /[^a-zA-Z]+/
如果您只想保留数字,请使用/[^0-9]+/
而不是/[^a-zA-Z]+/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.