I allow only one hyphen (-) in regex -
i have text box last name of user. how allow 1 hyphen (-) in regular expression?
^([a-z a-z]*-){1}[a-z a-z]*$
your regular expression allow 1 -
. assume want mach "smith", "smith-kennedy", not "smith-", must move hyphen second group:
^[a-z a-z]+(-[a-z a-z]+)?$
btw, in cases when *
used +
better solution.
Comments
Post a Comment