Reputation: 1392
How can i validate following logic from regex
Allowed string Example:
Does not allow : - $999999999.99 ( 9 digit before decimal) - $99,99,999,99.99
Mean i want to restrict the count of digit only before decimal. How can i achieve this. Thanks in Advance
Upvotes: 3
Views: 3928
Reputation: 785058
You can use this regex:
/^\$?(?:,?\d){1,8}(?:\.\d{1,2})?$/gm
Explanation:
^ # Line start
\$? # match optional $ at start
(?:,?\d) # Match an optional comma followed by a digit and use non-capturing group
{1,8} # up to 8 occurrence of previous group
(?:\.\d{1,2})? # followed by optional decimal point and 1 or 2 digits
$ # line end
Upvotes: 4