javascript - RegEx- Validate negative and positive decimal numbers -
i trying build regex allow both negative , positive decimal numbers following rules.
- there can not more 2 digits after decimal point
- decimal point optional
- total length including decimal point should not exceed 12 char
- if no decimal point there, max length should not exceed 9 char
can me out? lot in advance.
check regex.
^[+-]?[0-9]{1,9}(?:\.[0-9]{1,2})?$
this regex says
- sign optional
- at least 1 , max 9 digits integer part
- if decimal point there, @ least 1 , max 2 digits after it.
Comments
Post a Comment