How to use regex for names

Hi I have this regex

Regex re = new Regex(@"^[a-zA-Z]+$");

for firstname or lastname

the issue I have is it will not except

'
-

Can someone please change the regex so that it works with what I have already

thanks
mousemat24Asked:
Who is Participating?
 
Steve813Connect With a Mentor Commented:
Try this for your Regex

^[a-zA-Z'-]{5,20}$

Open in new window

0
 
jdavistxCommented:
What's an example of your input?

Regular expressions are sometimes overkill.  You may be able to achieve the same result with some easier-to-understand string manipulations.
0
 
mousemat24Author Commented:
I have this code

Regex re = new Regex(@"^[a-zA-Z]+$");
re.IsMatch(lastName))

0
 
mousemat24Author Commented:
I also want

min char 5
max chars 20

using regex
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.