I have the following regular expression:
^[-+]?[\d{0,3},?\d{3}]*\.?\d+$
I am trying to support numbers of the following formats:
I am not concerned about scientific notation but my users may or may not enter in commas. The problem I am having is that the expression is matching:
How can I have the expression indicate that if there is a comma then there must be three characters after it.
Try this regular expression:
/^[-+]?(?:\d*|\d{1,3}(?:,\d{3})*)(?:\.\d+)?$/
Try this
^([-+]?\d(?:(,\d{3})|(\d*))+\d*)?\.?\d*$
SUCCESSES
0
1
-1
-1.00
100,000
100.0
1,111,111
.25
FAILURES
100.0.
100.0,
asdf100.0
100,
1,11,111
,111,111
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With