Could anyone please provide me with a regular expression to allow only digits (0-9) excluding even '.' (decimal point) in a textbox in JSP using javascript. I would be using it to replace the resricted characters with '' (empty string).
I tried few but they are not restricitng the DOT.
Thanks in advance
正则表达式模式为:
/^[0-9]+$/
You need to anchor the regex:
/^\d*$/
to make sure that the entire string consists of digits.
Without ^
and $
, the regex would match 1
(and 234
) in 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 ""
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.