client side validation of email id

Posted by Sagarp under ASP.NET category on | Views : 3058
Steps 1:aspx page

Email : <asp:TextBox ID="txtEmail" />

aspx page->source:
%@ Page Language="C#" AutoEventWireup="true" CodeFile="demo.aspx.cs" Inherits="demo" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
function mailvalidate()
if (document.getElementById("<%=txtName.ClientID%>").value=="")
alert("Name Feild can not be blank");
return false;
if(document.getElementById("<%=txtEmail.ClientID %>").value=="")
alert("Email id can not be blank");
document.getElementById("<%=txtEmail.ClientID %>").focus();
return false;
var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
var emailid=document.getElementById("<%=txtEmail.ClientID %>").value;
var matchArray = emailid.match(emailPat);
if (matchArray == null)
alert("Your email address seems incorrect. Please try again.");
document.getElementById("<%=txtEmail.ClientID %>").focus();
return false;
<form id="form1" runat="server">
<asp:TextBox ID="txtEmail" />
<asp:Button ID="btnSubmit" OnClientClick=" return mailvalidate()" runat="server" Text="Submit" />

Comments or Responses

Login to post response