Comma Separated Numbers Regex

[0-9]+(,[0-9]+)+

This works better for me for comma separated numbers in general, like: 1,234,933


/^\d+(,\d+)*$/
  • for at least one digit, otherwise you will accept 1,,,,,4

[0-8,]* will match zero or more consecutive instances of 0 through 8 or ,, anywhere in your string. You want something more like this:

^[1-8](,[1-8])*$

^ matches the start of the string, and $ matches the end, ensuring that you're examining the entire string. It will match a single digit, plus zero or more instances of a comma followed by a digit after it.

Tags:

Regex