Step 1:- JavaScript Code
<script type="text/javascript">
function ValidateEmailAddress(emailAddress) {
emailAddress
= document.getElementById(emailAddress).value;
if (emailAddress
== "" || emailAddress == "Enter
E-mail") {
return false;
}
var emailPattern
= /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
var matchArray
= emailAddress.match(emailPattern);
if (matchArray
== null) {
alert("Invalid
Email Id.");
return false;
}
var ext
= emailAddress.substring(emailAddress.lastIndexOf("@") +
1);
var digits
= "(~`!#$%^&*+|=}{'?/)";
var temp;
for (var i
= 0; i < ext.length; i++) {
temp
= ext.substring(i, i + 1);
if (digits.indexOf(temp)
>= 0) {
alert("Invalid
Email Id.");
return false;
}
}
return true;
}
</script>
Step 2:- Design Page
<table style="border: 1px; width: 500px;">
<tr>
<td style="width: 200px;">
<label for="emailid">Email
Id:</label>
</td>
<td style="width: 200px;">
<asp:TextBox ID="emailid" runat="server" placeholder="Enter
E-mail" ClientIDMode="Static" onchange="return
ValidateEmailAddress('emailid')"></asp:TextBox>
</td>
</tr>
</table>
Step 3:- Complete Code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="
Default.aspx.cs" Inherits="Demo.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Validate
Email Address</title>
<script type="text/javascript">
function ValidateEmailAddress(emailAddress) {
emailAddress
= document.getElementById(emailAddress).value;
if (emailAddress
== "" || emailAddress == "Enter
E-mail") {
return false;
}
var emailPattern
= /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
var matchArray
= emailAddress.match(emailPattern);
if (matchArray
== null) {
alert("Invalid
Email Id.");
return false;
}
var ext
= emailAddress.substring(emailAddress.lastIndexOf("@") +
1);
var digits
= "(~`!#$%^&*+|=}{'?/)";
var temp;
for (var i
= 0; i < ext.length; i++) {
temp
= ext.substring(i, i + 1);
if (digits.indexOf(temp)
>= 0) {
alert("Invalid
Email Id.");
return false;
}
}
return true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="border: 1px; width: 500px;">
<tr>
<td style="width: 200px;">
<label for="emailid">Email
Id:</label>
</td>
<td style="width: 200px;">
<asp:TextBox ID="emailid" runat="server" placeholder="Enter
E-mail" ClientIDMode="Static" onchange="return
ValidateEmailAddress('emailid')"></asp:TextBox>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>