Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a text box for mobile no.I want to validate it as it can accept only 10 digit mobile no and no alphabets.
please reply soon.
Posted

Solution to ur prob:

XML
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
        ControlToValidate="TextBox1" ErrorMessage="Please enter valid Mobile number!"
        ValidationExpression="^([7-9]{1})([0-9]{9})$"></asp:RegularExpressionValidator>




mark it if it helps.........
 
Share this answer
 
Comments
ridoy 29-Oct-12 7:10am    
+5
C#
Regex.IsMatch("Your Mobile number", @"^[0-9]{10}+$");
 
Share this answer
 
Comments
ridoy 29-Oct-12 7:11am    
+5
Sushil Mate 29-Oct-12 7:58am    
thanks ridoy.
Use this regular expression to match ten digits only:

@"^\d{10}$"


Hope that helps!
 
Share this answer
 
XML
Hi PreetSidhu15,

Use below code


<asp:TextBox ID="txtMobile" runat="server" Width="150" CssClass="txt" MaxLength="10"></asp:TextBox>
                                <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender2" runat="server" Enabled="True"
                                    FilterType="Numbers" TargetControlID="txtMobile" ValidChars="0123456789">
                                </cc1:FilteredTextBoxExtender>
                                <asp:RequiredFieldValidator ControlToValidate="txtMobile" ID="RequiredFieldValidator1"
                                    ValidationGroup="Continue" CssClass="errormesg" ErrorMessage="Required Field"
                                    runat="server" Display="None" SetFocusOnError="true">
                                </asp:RequiredFieldValidator>
                                <cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender1" runat="server" TargetControlID="rr5">
                                </cc1:ValidatorCalloutExtender>
 
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