I have a text box where i get the last name of user. How do I allow only one hyphen (-) in a regular expression?
^([a-z A-Z]*-){1}[a-z A-Z]*$
A problem with your regex is that it forces the user to put a -. You can use ? to make it optional :
-
?
^[a-z A-Z]*\-?[a-zA-Z]*$