I need a RegEx to match the following:
1.234.567
-1.234.789
1234567
-1234567
It should not match:
.123 (leading separator)
123..456 (two separators)
In other words, I need a RegEx to match long
numeric values formatted with or without thousand separators.
Thanks!
Here is a more restricted answer
^-?(?!0)(?:\d+|\d{1,3}(?:\.\d{3})+)$
See it online here at Regexr
(?!0)
prevents from starting with 0
\d+
allows the numbers without separator
\d{1,3}(?:.\d{3})+
is the part for the separator. Start with 1 to 3 numbers, then a separator and 3 numbers. The dot for the separator followed by 3 numbers can be repeated.
You could do something like
^-?([0-9]{1,3}\.?)+$
RegExr Demo
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