Home > Code > Javascript > Validating Email address using regular expression in JavaScript

Validating Email address using regular expression in JavaScript

by Thamil   on Jun 09, 2011   Category: Javascript   |  Views: 4608    |  Points: 25   |  Gold 


Below sample JavaScript code shows how to validate the email address in the textbox. This is easy way to validate email address using regular expression.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/
TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Validate E-mail Address</title>
<script language="javascript" type="text/javascript">
function ValidateEmail(objEmail)
{
var reg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
if (!reg.test(objEmail.value))
{
alert('Not a valid e-mail Address');
return false;
}
}
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtEmail" onblur="javascript:ValidateEmail(this)" runat="server">
</asp:TextBox>
</div>
</form>
</body>
</html>







Post Code  |  Code Snippet Home

User Responses


No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts