Reputation: 33
I have a list of comma separated values:
123 should fail // using my regex this pass
123, 230 should pass
234, 560, 890 should pass
using this regex ^(\d+(, \d+)*)?$
if it is a single value, it still passes.
How can I only match 2 or more integers in the list?
Upvotes: 3
Views: 114
Reputation: 62546
You should use the +
instead of *
to make sure teh (, \d+)
part exists at least 1 time.
^(\d+(, \d+)+)?
Check this:
https://regex101.com/r/yvWiZ0/1
Upvotes: 1