Monday 7 September 2015

Validate Indian mobile no In Asp.net Webform...

Validate Indian mobile no In Asp.net Webform...  Now i am going to discuss about how to validate a Indian Mobile Number.   ... thumbnail 1 summary




Validate Indian mobile no In Asp.net Webform... 

Now i am going to discuss about how to validate a Indian Mobile Number.

              It should not accept any Aplhabets , or any special characters for this you have to write RegularExpression Validator to Accept only Numbers
 
EX: 
Regex \d+

the RegularExpressionValidator to validate the phone number without using JavaScript. So something like this: 
<asp:regularexpressionvalidator id="RegularExpressionValidator1"> ControlToValidate="TextBox1" ValidationExpression="\d+" Display="Static" EnableClientScript="true" ErrorMessage="Please enter numbers only" runat="server"/>
 
Atlast i have to check whether user entered Number is 10 digit or not and also it should be valid Mobile Number
Regex  ^[9][0-9]{9}$


This Regex which first digit should be 9 then followed by 9 digits and totally it accept only 10 digits.
So something like this: 
<asp:regularexpressionvalidator id="RegularExpressionValidator1"> ControlToValidate="TextBox1" ValidationExpression="^[9][0-9]{9}$" Display="Static" EnableClientScript="true" ErrorMessage="Please enter numbers only" runat="server"/>

 

1 comment