Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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 20:25pm
Rate this: bad
good
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.
 

--Amit
  Permalink  
Rate this: bad
good
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.
  Permalink  
Comments
Manohar Khillare at 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
0 Sergey Alexandrovich Kryukov 499
1 OriginalGriff 461
2 sanket saxena 325
3 Tadit Dash 285
4 Abhinav S 275
0 Sergey Alexandrovich Kryukov 12,159
1 OriginalGriff 7,421
2 Peter Leow 5,061
3 Abhinav S 4,073
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web01 | 2.8.140421.2 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid