Click here to Skip to main content
12,298,983 members (51,637 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
Hello, Iam using a textbox which have mobile number,so I need to validate the number ,and I use requied field validator and regular expression validator ,also I use the espression(up to 10 digits) ,but the problem is if the mobile number have 10 zeros(0000000000) regular expression will not validate ,plz help to solve this..its urgent....
here is the code

<td>
                                           <asp:Label ID="lblMobile" runat="server" Text="Mobile Number" Font-Bold="True" ForeColor="Black"></asp:Label>
                                       </td>
                                       <td>
                                           <asp:TextBox runat="server" ID="txtMobileNumber" MaxLength="10" OnCopy="return false"
                                               OnPaste="return false" CssClass="popuptxtbox" onkeypress="return isNumberKey(event);"
                                               onkeyDown="checkTextAreaMaxLength(this,event,'11');" onblur="return valid(this,'restric_spec');"></asp:TextBox>
                                       </td>
                                       <td>
                                           <asp:RequiredFieldValidator ID="rfvMobileNumber" runat="server" ErrorMessage="*"
                                               ControlToValidate="txtMobileNumber" SetFocusOnError="true"></asp:RequiredFieldValidator>
                                       </td>
                                       <td>
                                           <asp:RegularExpressionValidator ID="rfvMobile" runat="server" ControlToValidate="txtMobileNumber"
                                               ErrorMessage="Minimum 10 digits" SetFocusOnError="True" ValidationExpression="^((\+)?(\d{2}[-]))?(\d{10}){1}?$"></asp:RegularExpressionValidator>
                                       </td>
Posted 7-Nov-12 19:31pm
Comments
biswarup88 8-Nov-12 2:13am
   
did you google this topic? you'll get javascript to validate mobile no field.
faisal23 8-Nov-12 5:49am
   
use range validator and set min -0000000000 and max 9999999999 and type int

1 solution

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

Solution 1

Use this regex

^((\+)?(\d{2}[-]))?(\d{10}){1}?$
  Permalink  

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 | Mobile
Web02 | 2.8.160525.2 | Last Updated 9 Nov 2012
Copyright © CodeProject, 1999-2016
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