1.449,00
1.000.000,55
19,90
etc
etc
I know what I listed above are very variable but there are possibilities for currency. I\'m looking for a
Add +
after the ]
to allow more than just one character.
Something like this should work:
/^((?:\d{1,3}[,\.]?)+\d*)$/
This matches:
^ - Start of string
( - Capture the following:
(?:
\d{1,3} - One to three digits
[,\.]? - And an optional separator (comma or period)
)+ - One or more times
\d* - Zero or more digits
)
$ - End of string
It works by iteratively matching everything to the left side of the separator (if it's present), and then has \d*
to pick up any optional fractions of currency.
You can see it passes all of your tests.
Edit: An updated regex looks like this:
^((?:\d\.\d{3}\.|\d{1,3}\.)?\d{1,3},\d{1,2})$
Where we match either:
\d\.\d{3}\.
- One digit, a period, three digits, a period, OR\d{1,3}\.
- One and three digits, a period?
)Then, we match:
\d{1,3},
- One to three digits and a comma, followed by\d{1,2}
- One or two digits