How to use regex for names

Posted on 2011-04-27
Last Modified: 2012-05-11
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

Question by:mousemat24
    LVL 7

    Expert Comment

    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.

    Author Comment

    I have this code

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


    Author Comment

    I also want

    min char 5
    max chars 20

    using regex
    LVL 1

    Accepted Solution

    Try this for your Regex


    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    In one of my recent projects, I was working with IP cameras, I need to take some pictures from the camera and do some processing on it. The first step, was to retrieve the image from camera into Image object. So that it can be displayed or …
    Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
    This video discusses moving either the default database or any database to a new volume.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now