I have created a form which has two validation rules for the e-mail field, one to check the format and the other to check that the two e-mail addresses entered are the same.
I’ve been Googling around and, from what I’ve seen, the onSubmit cannot have more than two return functions (unless someone can correct me on this?). Therefore, I have been trying to put the two validation rules into one function but, because I’m such a newbie at JavaScripting, I can’t get them to work. I have tested both rules seperately and they work fine, I just can’t seem to put them together.
Or are there other, better ways to do this?
Here are the two functions:
[U]Function 1
function verify_email(email, email_conf)
{
if (email.value == ” || email_conf.value == ”)
{
alert(‘Please fill out both e-mail fields.’);
return false;
}
else if (email.value != email_conf.value)
{
alert(‘The e-mail addresses entered do not match.’);
return false;
}
else
{
md5hash(email, document.email_us.form1.email);
md5hash(email_conf, document.email_us.form1.email_conf);
return true;
}
return false;
}
[U]Function 2
function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf(“@”)
ipos=value.indexOf(“.”)
dotpos=value.lastIndexOf(“.”)
if (apos<1||ipos<1||dotpos-apos<2)
{alert(alerttxt);return false}
else {return true}
}
}
function validate_form(thisform)
{
with (thisform)
{
if (validate_email(email,”Please include a valid e-mail address”)==false)
{email.focus();return false}
}
}
Any help would be much appreciated.