Try
/^\d+(-\d+)?(,\d+(-\d+)?)*$/
Further to the comments
One way to prevent a match if there are consecutive ranges is to add a negative look-ahead
(?!.*-\d+,\d+-)
so the regex becomes
/^(?!.*-\d+,\d+-)\d+(-\d+)?(,\d+(-\d+)?)*$/
If the pattern inside the negative look-ahead can be matched it prevents the whole regular expression from matching. The .*
is used so that if e.g. -1,1-
is found anywhere ahead in the string, a match will be prevented.