How to validate email address using jQuery
In this article I'm going to explain how to validate the email address using jQuery.
In this article I'm going to explain how to validate the email address using jQuery.
To validate the email address, I have created a separate function to check whether email id is valid or not.
Email Validation is done using Regualr expression.
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" src="jquery-1.2.6.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#Button1').click(function() {
var vtxtEmail = $('#txtEmailID').val();
if ($.trim(vtxtEmail).length == 0) {
alert('Plz enter valid email address!');
e.preventDefault();
}
if (TovalidateEmail(vtxtEmail)) {
alert('This is not valid email id');
}
else {
alert('Invalid Email Address');
e.preventDefault();
}
});
});
function TovalidateEmail(vtxtEmail) {
var filterexpression = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (filterexpression.test(vtxtEmail)) {
return true;
}
else {
return false;
}
}?
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtEmailID" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
</body>
</html>