Reputation: 493
I'm trying to write a validation javascript regex to check a string is a comma delimited 6-digit string. For example:
123456
OR
123456,123456,123456
but NOT
123456,123
The regex I'm using is ^([0-9]{6})(\,[0-9]{6})*
. The problem I'm having is how to get the regex to fail on the last part, where it should fail since 123 is not a 6-digit number. I tired adding a $ to the end of the regex, but then it breaks the whole thing. Can someone help me so that the regex will FAIL unless the string is A) a 6-digit string or B) comma delimited 6-digit strings?
Upvotes: 3
Views: 515