Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
谁能给我一个正则表达式,只允许数字(0-9),甚至不包括“。” (小数点)在使用 javascript 的 JSP 中的文本框中。我会用它用''(空字符串)替换受限制的字符。
我尝试了一些,但他们并没有限制 DOT。
提前致谢
正则表达式模式将是:
/^[0-9]+$/
您需要锚定正则表达式:
/^\d*$/
确保整个字符串由数字组成。
没有^and $,正则表达式将匹配1(and 234) in 1.234。
^
$
1
234
1.234
I would use the class \d, it includes only digits. If you want to replace all non-digits you would need to replace \D+ with "".
\d
\D+
""