Regular expression to validate a firstname or a lastname

Posted on 2008-11-11
Last Modified: 2012-05-05
need to fix the regular expression for last name

                                                      <td class="physicalLightBox" align="left">
                                                      <div class="label">
                                                            <img height="14" src="images/starsmallfull.gif" width="15" />&nbsp;Last Name</div>
                                                      <td class="physicalLightBox" style="text-align: left;">
                                                      &nbsp;<asp:TextBox ID="txtLastName" MaxLength="50" runat="server" Width="155px" BorderStyle="Inset" BorderWidth="2px" BorderColor="DarkGray" />
            <asp:RequiredFieldValidator ID="RFVtxtLastName" runat="server"  ControlToValidate="txtLastName" ErrorMessage="<b>Required Field Missing.</b><br />Last Name is required." Font-Size="X-Small" SetFocusOnError="true" Display="None"></asp:RequiredFieldValidator>
            <ajaxToolkit:ValidatorCalloutExtender runat="Server" ID="RFVtxtLastNameE" TargetControlID="RFVtxtLastName" HighlightCssClass="validatorCalloutHighlight" />    
            <ajaxToolkit:ValidatorCalloutExtender ID="ValidatorCalloutExtender16" runat="server"
             <asp:RegularExpressionValidator ID="REVtxtLastName" runat="server" ControlToValidate="txtLastName" Font-Size="X-Small" SetFocusOnError="true" ValidationExpression="^[A-Z]{1}[a-zA-Z]{1,}$" ErrorMessage="<b>A valid Last Name name is required,</b><br />Please type between 2 to 75 letters<br />(avoid special characters and digits)" Display="None"></asp:RegularExpressionValidator>
             <ajaxToolkit:ValidatorCalloutExtender runat="Server" ID="REVtxtLastNameE" TargetControlID="REVtxtLastName" HighlightCssClass="validatorCalloutHighlight" />
         <ajaxToolkit:ValidatorCalloutExtender ID="ValidatorCalloutExtender18" runat="server"
Question by:mathieu_cupryk
    LVL 59

    Expert Comment

    by:Kevin Cross
    >>need to fix the regular expression for last name

    What is it doing OR not doing?

    Author Comment

    the message is coming up when I enter for example cupryk

    Please type between 2 to 75 letters<br />(avoid special characters and digits)"
    the above message.
    LVL 59

    Accepted Solution


    This is requiring first letter to be uppercase and then one or more letters that can be lower or uppercase.  If you don't care about case, then try this.


    Added upper bound as well since you are indicating only 75 characters max.

    Author Closing Comment

    i have aproblem with the postal codes
    iam posting anew question.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    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