简体   繁体   中英

Flex Regular expression help needed

I have created the regexp which allows me to enter == > (digit(0-9)).(digit(0-9) - for 2 decimal)

I am not sure how do I stop, to allow entering "0" more than once.

This is what i have tried:

/^[[0-9]]?[0-9]*\.?[0-9]{0,2}$/

But it also allows to enter value like 00000.2 , I wanted to stop user entering any value if its stars with 0. and allow only 0.2

Try this

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

See it here on Regexr

This allows 0 or a number starting with 1-9 before the dot. The fractional part is completely optional, but when it is existing, it need one or two digits after the dot.

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