How to validate 10 digit mobile number in asp.net with regular expression control.


Posted Date: Aug 23, 2011     Posted By: Vikash         
Hi all,

I need to validate 10 digit mobile number in asp.net.

How will I use of regular expression control for validate mobile number of 10 digit in asp.net

Please help me,

Thanks in advance
Response #1        Reply By: Aryan Basu         Posted Date: Aug 23, 2011        
        
Hi

you can use following code for 10 digit mobile number in asp.net with use of regular expression control.

RegularExpression for 10 digit:

^[0-9]{10}


<asp:RegularExpressionValidator id="RegularExpressionValidator1" runat="server" ControlToValidate="txt_mobilenumber" ErrorMessage="Please Enter 10 digit Mobile Number" ValidationExpression="^[0-9]{10}"></asp:RegularExpressionValidator>
Response #2        Reply By: Vikash         Posted Date: Aug 23, 2011        
        
Hi sir,

I need to validate telephone number which take only numeric value from 0-9 and 7-11 digit value .

Please reply the validationExpression value for this in RegularExpressionValidator Control; I am using RegularExpressionValidator for this.
Response #3        Reply By: Aryan Basu         Posted Date: Aug 23, 2011        
        
Hi vikash,

You can use below ValidationExpression for validate Telephone number for enter only numeric value and 7-11 digit value

<asp:TextBox ID="txt_telephone" runat="server" ></asp:TextBox>

<asp:RegularExpressionValidator ID="RegularExpressionValidator5" runat="server" Font-Size="10px" ControlToValidate="txt_telephone" Display="Dynamic" ErrorMessage="<br>Telephone Number must be 7-11 digit" ValidationExpression="^[0-9]{7,11}$"></asp:RegularExpressionValidator>

RegularExpression for 7-11 digit:

Validation expression ="^[0-9]{7,11}$"

[0-9] - means it will take only 0 to 9 Numeric value
{7,11} - means it will take number between 7 to 11 digit.