Hi i'm using the following to validate a users input box for email. I need to have all the messages associated with each miss-hap but was wondering if there was a more elegant way to accomplish what i have, thanks:
Code:
function ValidateEmail(strEmail) {
if(-1 == strEmail.indexOf("@")) {
document.all('EMail').focus();
alert("Your email must have a '@'.");
return false;
}
if(-1 == strEmail.indexOf(".")) {
document.all('EMail').focus();
alert("Your email must have a '.'.");
return false;
}
if(-1 != strEmail.indexOf(",")) {
document.all('EMail').focus();
alert("Your email must not have a ',' in it");
return false;
}
if(-1 != strEmail.indexOf("#")) {
document.all('EMail').focus();
alert("Your email must not have an '#' in it." );
return false;
}
if(-1 != strEmail.indexOf("!")) {
document.all('EMail').focus();
alert("Your email must not have a '!' in it." );
return false;
}
if(-1 != strEmail.indexOf("'")) {
document.all('EMail').focus();
alert("Your email must not have a ' in it." );
return false;
}
if(-1 != strEmail.indexOf(""")) {
document.all('EMail').focus();
alert("Your email must not have a " in it." );
return false;
}
if(-1 != strEmail.indexOf("%")) {
document.all('EMail').focus();
alert("Your email must not have a "%" in it." );
return false;
}
if(-1 != strEmail.indexOf("&")) {
document.all('EMail').focus();
alert("Your email must not have a "&" in it." );
return false;
}
if(-1 != strEmail.indexOf("+")) {
document.all('EMail').focus();
alert("Your email must not have a "+" in it." );
return false;
}
if(-1 != strEmail.indexOf(" ")) {
document.all('EMail').focus();
alert("Your email must not have a space in it." );
return false;
}
if(strEmail.length == (strEmail.indexOf("@")+1) ) {
document.all('EMail').focus();
alert("Your email must have a domain name after the '@'.");
return false;
}
if(strEmail.length == 0) {
document.all('EMail').focus();
return false;
}
return true;
}