0

I have numbers like this

12,555,666.0000 [valid]

125,636.0000 [valid]

1,256.0000 [valid]

12,56..0000[invalid]

12*565.54.00

Now I need a regex for this where I have to make sure

  1. This number does not contain a special character except(,) and just one decimal point (.)

I tried something like this ^[\d,]*\.{0,1}\d{0,4}$ but it doesn't work.

stema
  • 90,351
  • 20
  • 107
  • 135
Ankon
  • 43
  • 9
  • possible duplicate of [Currency Regular Expression](http://stackoverflow.com/questions/13848570/currency-regular-expression) – Huey May 04 '15 at 07:44

1 Answers1

0

You can try like this:

^\d+(\,\d{3})*(\.\d{1,4})?$
  1. Start with one or more digits ^\d+
  2. Followed by (comma and three digits) zero or more times (\,\d{3})*
  3. Followed by (point and 1 to four digits) zero or one time (\.\d{1,4})?
  4. End $

Example: https://regex101.com/r/uO4qX2/1

Danilo
  • 2,676
  • 7
  • 32
  • 36