Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

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
0
mousemat24
Asked:
mousemat24
  • 2
1 Solution
 
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
 
Steve813Commented:
Try this for your Regex

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

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now