Reputation: 1744
I need help in regex where first character alphabet only, second and onwards can be alphanumeric or special characters (hyphen, comma and whitespace).
I tried below its is not working.
^[a-zA-Z][a-zA-Z0-9 -,]+$
Upvotes: 1
Views: 602
Reputation: 20037
You were almost there, simply escape -
in the second character set, like so:
^[a-zA-Z][a-zA-Z0-9 \-,]+$
Otherwise, as pointed out by @Sweeper in the comments, -,
would match any character between and
,
.
See explanation.
Upvotes: 2