Jorge Oduber Jorge Oduber - 3 months ago 16
Dart Question

JavaScript regex to accept numbers with comma separator (thousands) and dot separator (decimals)

Could any of you help me with a regular expression which will accept these:

For every thousand a comma will be accepted.
No less than 4 decimal points in number

I've been testing this pattern but fails in some scenarios:

^\d+(\,\d+{1.3} \.d{1.4})*$


Valid inputs:

1
11
111
1,111
1,111,111
1.1111
11.1111
111.1111
1,111.1111


Invalid inputs:

Any letter
1,1
1.1
1.11
1,11.11
1,111.1


The main criterions are:
(4 decimal points are obligatory).
(3 numbers per thousand must have a comma.)

Answer

Is this more complicated than

/^\d\d?\d?(,\d\d\d)*(\.\d\d\d\d)?$/

or if you prefer

/^\d{1,3}(,\d{3})*(\.\d{4})?$/
Comments