Regex validation for numbers with comma separator

This should do it:

^\d+(,\d+)*$

The regex is rather simple: \d+ is the first number, followed by optional commas and more numbers.

You may want to throw in \s* where you see fit, or remove all spaces before validation.

  • To allow negative numbers replace \d+ with [+-]?\d+
  • To allow fractions: replace \d+ with [+-]?\d+(?:\.\d+)?

Leave a Comment