Here I will explain how to validate phone number with regular expression using Jquery in asp.net.
In previous articles I explained validate email address using JQuery in asp.net and many articles relating to JQuery. Now I will explain how to use regular expression to validate phone number using JQuery in asp.net.
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1"
runat="server">
<title>Regular expression to validate phone number using jquery in
asp.net</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function
() {
$("#btnValidate").click(function () {
var phoneText = $("#txtPhone").val();
if ($.trim(phoneText).length == 0) {
alert("Please
enter Phone Number");
return false;
}
if (validatePhone(phoneText)) {
alert('Valid
Phone Number');
return true;
}
else {
alert('Invalid Phone
Number');
return false;
}
});
});
function validatePhone(phoneText) {
var filter = /^[0-9-+]+$/;
if (filter.test(phoneText)) {
return true;
}
else {
return false;
}
}
</script>
</head>
<body>
<form id="form1"
runat="server">
<div>
<asp:TextBox ID="txtPhone"
runat="server"
/>
<asp:Button ID="btnValidate"
runat="server"
Text="Validate"
/>
</div>
</form>
</body>
</html>
|
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|

Subscribe by RSS
Subscribe by Email
5 comments :
I want Image Preview before upload in asp.net plz send me this code
I am using you code to do jquery validation for number and required fields.
I need regular express to validation US Zip code.
I am using this one
return this.optional(element) || /^\d{5}\-$|^\d{5}\-\d{4}$/.test(value);
when i enter only 5 digits it is not working.
I am using you code to do jquery validation for number and required fields.
I need regular express to validation US Zip code.
I am using this one
return this.optional(element) || /^\d{5}\-$|^\d{5}\-\d{4}$/.test(value);
when i enter only 5 digits it is not working.
I want the code for the mail confirmation means if the user forgot its password then by entering his mail id the password is sent ti his mail. myid is abhigupta3189@gmail.com Thanks in advance.
Hiii Suresh Sir,
I want the validation in c# and VB.net like this
if we enter only 2 numbers in the text it throw an error and only 10 numbers can insert and which can strats with 9,8,7 like this