helloworld
helloworld

Reputation: 965

Regex to validated 10 occurrences of comma separated numerical values

I need to validate text field to accept only numbers. There can be 0 through 10 occurrences of numbers separated by commas.

Here is what I have done so far.

/^[0-9]$(?:[,][0-9]){0,9}$/i

this validated the comma separated numerical values, but not restricting it to 10 occurrences.

sample inputs : 1002,1003,1004,1005,1006,1007,1008,1009,1010

can someone show me the mistake?

Upvotes: 1

Views: 315

Answers (1)

anubhava
anubhava

Reputation: 784898

You can use:

/^(\d+(?:,\d+){0,9})?$/

This will also accept blank string as valid input.

Upvotes: 2

Related Questions