Link to home
Start Free TrialLog in
Avatar of mousemat24
mousemat24

asked on

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
Avatar of jdavistx
jdavistx

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.
Avatar of mousemat24

ASKER

I have this code

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

I also want

min char 5
max chars 20

using regex
ASKER CERTIFIED SOLUTION
Avatar of Steve813
Steve813
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial