Friday, October 21, 2011
Mobile validation on Textbox
u can validate mobile no as follows using RegularExpressionValidator<td>
<asp:TextBox id="TextBox1"
runat="server"/>
</td>
<td>
<asp:RegularExpressionValidator id="RegularExpressionValidator1"
ControlToValidate="TextBox1"
ValidationExpression="\d{10}"
Display="Static"
EnableClientScript="false"
ErrorMessage="Mobile noumer must be 10 numeric digits"
runat="server"/>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="Button1" text="Validate"
OnClick="ValidateBtn_Click"
runat="server"/>
</td>
Mobile number textbox validation
string pattern = @"^\d{10}$";
string data = "111111111111";
if (Regex.IsMatch(data, pattern))
{
Console.WriteLine("Match");
}
else
{
Console.WriteLine("Not a Match");
}
Include a reference to the namespace System.Text.RegularExpressions
se regular expression to validate the mobile number
This below expressions will accept the country code as optional and the phone number as 10 digit number.<script language="JavaScript">
function phone_validate(phone)
{
var phoneReg = ^((\+)?(\d{2}[-]))?(\d{10}){1}?$;
if(phoneReg.test(phone) == false)
{
alert("Phone number is not yet valid.");
}
else
{
alert("You have entered a valid phone number!");
}
}
</script>Thanks,