Decimal Regex Constraint Matching (Four digits before optional decimal point and two after) -


i need figure out how make regex allow match correctly each time type number/decimal point. want limit number of digits before , after decimal point, isnt hard cant figure out how allow decimal point match well.

1 - match 12 - match 1234 - match 12345 - wrong 1234. - match 1234.1 - match 1234.12 - match 1234.123 - wrong  other matched numbers 12.12 1.0 123.99 

edit:

so want max of 4 numbers before decimal place , 2 after. decimal place optional.

the tricky part want fail if fifth character isn't decimal point.

you need specify constraints better; i'm assuming want maximum of 4 before dot , 2 after:

/^\d{1,4}(\.\d{0,2})?$/

edit: added beginning , end of string matchers. should work want now


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -