Reputation: 247
How should I write regex to validate below conditions:
eg: Valid strings: 1234, EC123, 1YC898, 001234
So far, I have tried below regex, but seems like I am missing something?
(^[a-zA-Z0-9]{4,6})?\d{3}$
Upvotes: 1
Views: 4728
Reputation: 786146
You can use:
^[a-zA-Z0-9]{1,3}\d{3}$
^[a-zA-Z0-9]{1,3}
will match 1 to 3 alpha-numerals at the start\d{3}$
will match 3 digits at the end of your inputUpvotes: 5