Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
4.33/5 (3 votes)
See more:
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

XML
<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
Comments
sahabiswarup 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

Use this regex

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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900