Click here to Skip to main content
Rate this: bad
good
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 at 8-Nov-12 2:13am
   
did you google this topic? you'll get javascript to validate mobile no field.
faisal23 at 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
0 Sergey Alexandrovich Kryukov 404
1 Nirav Prabtani 389
2 Abhinav S 210
3 PIEBALDconsult 160
4 Dave Kreskowiak 155
0 OriginalGriff 7,580
1 Sergey Alexandrovich Kryukov 6,806
2 Maciej Los 3,919
3 Peter Leow 3,693
4 CHill60 2,742


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 9 Nov 2012
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