正则表达式删除字母,符号除数字 [英] Regex to remove letters, symbols except numbers
本文介绍了正则表达式删除字母,符号除数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何删除字母,符号,例如∞§¶•ªºº«≥≤÷
但是保留0-9的普通数字,我希望不能允许输入字段中的字母或某些符号,但只留下数字。
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.
演示。
如果您放置任何符号,如¡#¢¶¶•ª
,否则它仍然不会从输入字段中删除它。你如何删除符号? \ w
修饰符也不起作用。
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.
推荐答案
你可以使用 \D
表示非数字。
var removedText = self.val().replace(/\D+/g, '');
jsFiddle 。
你也可以使用 HTML5 号码输入。
You could also use the HTML5 number input.
<input type="number" name="digit" />
jsFiddle 。
这篇关于正则表达式删除字母,符号除数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文