Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Regular expression to validate a firstname or a lastname

Posted on 2008-11-11
4
Medium Priority
?
355 Views
Last Modified: 2012-05-05
need to fix the regular expression for last name

<tr>
                                                      <td class="physicalLightBox" align="left">
                                                      <div class="label">
                                                            <img height="14" src="images/starsmallfull.gif" width="15" />&nbsp;Last Name</div>
                                                      </td>
                                                      <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"
            TargetControlID="RFVtxtLastName">
            </ajaxToolkit:ValidatorCalloutExtender>
       
             <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"
            TargetControlID="REVtxtLastName">
        </ajaxToolkit:ValidatorCalloutExtender>
                                                     </td>
                                                </tr>
0
Comment
Question by:mathieu_cupryk
  • 2
  • 2
4 Comments
 
LVL 60

Expert Comment

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

What is it doing OR not doing?
0
 

Author Comment

by:mathieu_cupryk
ID: 22936457
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.
0
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 2000 total points
ID: 22936610
="^[A-Z]{1}[a-zA-Z]{1,}$"

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.

="^[a-zA-Z]{1}[a-zA-Z]{1,74}$"

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

Author Closing Comment

by:mathieu_cupryk
ID: 31515815
i have aproblem with the postal codes
iam posting anew question.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Integration Management Part 2
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month21 days, 4 hours left to enroll

810 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