I had a requirement where in the text field the first character should be a alpha numeric and then i can allow a hyphen from thereafter in JavaScript.Also hyphen should not be allowed at the end
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With