Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

jQuery Email Address Validation with Regular Expression in Asp.net

Jul 23, 2012
Introduction

Here I will show how to validate email address using jQuery with regex or regular expression or validate email address in jquery using regular expression or email validation using jQuery in asp.net.

Description:
  
In previous articles I explained how to disable or enable all the controls on page using JQuery and many articles relating to JQuery. Now I will explain how to use regular expression to validate email address using JQuery in asp.net.

To implement this one we need to write code as shown below in your aspx page

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Regular expression to validate email 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 EmailText = $("#txtEmail").val();
if ($.trim(EmailText).length == 0) {
alert("Please enter email address");
return false;
}
if (validateEmail(EmailText)) {
alert('Valid Email Address');
return true;
}
else {
alert('Invalid Email Address');
return false;
}
});
});
function validateEmail(sEmail) {
var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (filter.test(sEmail)) {
return true;
}
else {
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtEmail" runat="server"/>
<asp:Button ID="btnValidate" runat="server" Text="Validate" />
</div>
</form>
</body>
</html>
If you observe above code in header section I added script file link by using that file we have a chance to interact with JQuery and in the script we have btnValidate button click function which is used to validate email address based using JQuery in asp.net.

Demo


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 RSS subscribe by email Subscribe by Email

2 comments :

Anonymous said...

hi suresh
when i am entering email like "aa@gmail.com.com",message should be display "Valid Email" but this is not a valid email.

Anonymous said...

hi suresh
when i am entering email like "aa@gmail.com.com",message display "Valid Email" but this is not a valid email.

Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.