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

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -