7

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!

Olav Haugen
  • 1,301
  • 2
  • 11
  • 20

2 Answers2

9

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.

stema
  • 80,307
  • 18
  • 92
  • 121
2

You could do something like

^-?([0-9]{1,3}\.?)+$

RegExr Demo

kapa
  • 72,859
  • 20
  • 152
  • 173