Reputation: 69
I want to validate whether the user enter data in this form B101,202,BBB,B902,Z-102 That is each value can be only of alphabets, digits or alphanumeric + '-' Tried this expression but it failed for alphabets and digits only condition. ^[A-Za-z0-9]+(,[A-Za-z0-9]+)*[A-Za-z0-9]+$
Upvotes: 2
Views: 2611
Reputation: 402
Please try the following regex
^[A-Z0-9]+((,|-)[A-Z0-9]+)*[A-Z0-9]+$
This checks the following:
You can try it online at Regexr.com
Upvotes: 3