Comma Separated Numbers Regex

[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.

Leave a Comment