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 21:25pm
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
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  

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

  Print Answers RSS
0 Maciej Los 295
1 OriginalGriff 259
2 Sergey Alexandrovich Kryukov 205
3 Aajmot Sk 187
4 Sinisa Hajnal 176
0 OriginalGriff 7,800
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2014
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