简体   繁体   中英

Regex for decimal input in Javascript having 1 to 3 digits before decimal and 1 to 3 digits after decimal

I wanted to create a Javascript regex, which accepts

123, 123.123, 12.34, 1.324

But should not accept

1246, 1234.45, 1.2364

试试这个正则表达式:

/^[0-9]{1,3}(\.[0-9]{1,3})?$/

尝试这个

/^\d{1,3}(\.\d{1,3})?$/

Try this one:

/^(0|[1-9]\\d?\\d?)(\\.\\d{1,3})?$/

I assume "00" or "01.234" should not be valid. Use the other answers if they should. :)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM