Reputation: 2785
I have this regular expression /^\d(\d|\,\d{3}|,\d.+$)*$/
With my sample data:
100.00 - Not working :(
1,000.00 - Working
100,000.00 - Working
1,000,000.00 - Working
Note: I need to give error if result is 0.00
Any ideas or suggestions? Thanks.
Upvotes: 17
Views: 64063
Reputation: 670
A symbol version
^([^\d\s]{1,}\s?[+-]?)(\d{1,3})(\,\d{3})*(\.\d{1,})?$
Will check
Upvotes: 0
Reputation: 71538
You could perhaps use:
^(?!0\.00)\d{1,3}(,\d{3})*(\.\d\d)?$
See how it's working here.
Additionally, if you'd like to forbid leading zeros the regex would be:
^(?!0\.00)[1-9]\d{0,2}(,\d{3})*(\.\d\d)?$
Upvotes: 23
Reputation: 75
You can use:
^\$?(?!0.00)(([0-9]{1,3},([0-9]{3},)*)[0-9]{3}|[0-9]{1,3})(\.[0-9]{2})?$
It will check
100.00 - yes
1,000.00 - yes
100,000.00 - yes
1,000,000.00 - yes
0.00 - no
Upvotes: 1