I have a nice challenge for those who like regex; like me. Unfortunately, I cannot figure this one out.
This regex is a reverse match. I need to match everything but a proper amount; like:
These types need to NOT MATCH:
0,00
0.00
12314345.7
24234.54
34435,00
34545,43
These types need to MATCH:
.00
,87
1e3,67
So everything but a decimal amount with a comma or point needs to match in JavaScript (yes, reverse).
I have made this:
([^0-9]+([^\.,]{0,1})+[^0-9]{0,2})
But, obviously, it doesn't work properly seeing it passes through multiple comma's or dots and doesn't limit the decimals to a maximum of two.
Solution using a negative lookahead:
^(?!\d+([,.]\d{0,2})?$).*$
http://regex101.com/r/jY3tC3
Note: This regex needs anchoring. I've anchored between ^
and $
.
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