Issue
I have tried below regular expression to validate the number with following criteria
/^\d{3,10}(\.\d{2})?$/
a, number should be minimum 3 , maximum 10 (including .) digits and it may contain . and two decimal point
Examples
valid numbers
123
1234
12345
123456
1234567
12345678
123456789
1234567890
123.00
1234.02
12345.03
123456.04
1234567.05
Invalid numbers
1
12
1.11
1.1111
12345678.12
But my regex fail in case of 1234567890.00
Solution
You can use:
^(?![.\d]{11,}$)\d{3,10}(?:\.\d\d)?$
Explanation
^
Start of string(?![.\d]{11}$)
Negative lookahead, assert not 11 or more digits or dots till the end of the string\d{3,10}
Match 3-10 digits(?:\.\d\d)?
Optionally match.
and 2 digits$
End of string
See a regex demo.
Answered By - The fourth bird
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.