Possible Duplicate:
Validate email address in Javascript?
I am trying to use this javascript to check for a valid email, but what I don't need it to do is check to see if the field is blank in the form in case someone doesn't have an email address (don't ask).
function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
if (apos<1||dotpos-apos<2)
{alert(alerttxt);return false;}
else {return true;}
}
}
function validate_form(thisform)
{
with (thisform)
{
if (validate_email(email,"Not a valid e-mail address.")==false)
{email.focus();return false;}
}
}
I tried to adjust the apos<1 to less than 1 or nothing at all and that didn't seem to work.