RegEx for allowing alphanumeric at the starting and hyphen thereafter

If you do not want to match mutiple dashes after eachother:

^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$

This will match: a, a-a, aaa-a, aaa-a-aaa-a-aaa-a, etc
But not: -, -a, a-, a--a, a-a-a-, a-a--a, etc.

Leave a Comment