1

Hy guys i need to implement a money format data validation, i need this regex only accept the following formats: Note: Only accept two or one positions for decimal before dot, the commas are optional every 3 digits

1
1.0
1.00
100.00
1,000.00
1000.00
111,000.00
111000.00
999,999,999.00

Assuming the Dot and commas are optionals.

Wrong Formats:

,1.00
1.
1,,00.00
1.000
etc
  • 1
    possible duplicate of [RegEx to match comma separated numbers with optional decimal part](http://stackoverflow.com/questions/1565994/regex-to-match-comma-separated-numbers-with-optional-decimal-part) – David says Reinstate Monica Feb 20 '15 at 22:19
  • 1
    This is not a duplicate since the requirements differ. – Wiktor Stribiżew Feb 20 '15 at 22:23
  • 1
    There are two critical pieces of information missing from this question. You need to tell us 1) **what language / platform you're using** as each regex engine has its own quirks, and 2) **what have you tried** before you came here and why your attempt didn't work. – p.s.w.g Feb 20 '15 at 22:26
  • @DavidGrinberg This Regex has other requirements. – Gozfly Hosting Feb 20 '15 at 22:32

1 Answers1

1

This one can help:

^\d+(?:,\d+)*(?:\.\d|\.\d\d)?$

See demo

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563