Click here to Skip to main content
13,408,861 members (44,669 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have 2 validaion control which is used to validate mobile number below is source code
<asp:TextBox ID="txtMobileNumber1" runat="server" Width="200px"></asp:TextBox>

<asp:RegularExpressionValidator ID="revMobileNumber1" runat="server"

ControlToValidate="txtMobileNumber1" ErrorMessage="Please Enter Number Only"ForeColor="Red" ValidationExpression="^\d+$"></asp:RegularExpressionValidator>

<asp:RegularExpressionValidator ID="RegularExpressionValidator1"  runat="server"ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}" ErrorMessage="Mobile Number should be 10 Digit" ControlToValidate="txtMobileNumber1"></asp:RegularExpressionValidator>

I want if user enter charcater than it display first error "please enter number" and second error should not display "Mobile Number should be 10 digit".but in my case it display both error message.i want only one message at time. i have only one button control.
Posted 4-Feb-13 21:25pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

It's quite tough to Judge the validator events, which will fire first. Rather you can go for Javascript using same RegularExpression.

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Why don't you try custom validator and write your own javascript function and put your logic.
And show the error message as per your requirement.
Manohar Khillare 5-Feb-13 2:38am
Is there way to display error in same place

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01-2016 | 2.8.180212.1 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100