Use following functions for email validation. this will also validate domain values.. e.g. below functions will only validate emails having yahoo.com and gmail.com as domains.
function validate()
{
var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+$/;
if(!pattern.test(Email))
{
alert("Enter a valid E-mail ID.");
document.getElementById('<%=txtEmail.ClientId %>').value ="";
document.getElementById("<%=txtEmail.ClientId %>").focus();
return false;
}
var res = isValidDomain();
if (res==0)
{
return false;
}
}
function isValidDomain()
{
var Domain = "yahoo.com;gmail.com";
var DomainList=Domain.split(",");
var Email = document.getElementById("<%=txtEmail.ClientId %>").value;
var userDomains = Email.split("@");
var userDomain=userDomains[1]
var part_num=0;
var result=0;
while (part_num < DomainList.length)
{
var srtdomain = DomainList[part_num];
part_num+=1;
if (srtdomain.toUpperCase()==userDomain.toUpperCase())
{
result=1;
break;
}
}
if (result==0)
{
var email = document.getElementById("<%=txtEmail.ClientId %>")
email.disabled=false;
alert("Enter a valid Domain Name.");
document.getElementById("<%=txtEmail.ClientId %>").focus();
}
return result;
}