javascript form validation - matching email fields
This is my form validation for the email address - field email1 - what I need to do is add a second validation - email1 is equal to email2 and if not, then a different alert message displays. I tried to add:
if (f.email1.value != f.email2.value)
{
customAlert ("email2",bnadd_msg_005);
return (false);
}
But that didn't work for me. Any insight?
case "email1":
// Checking to make sure email field is on the form
if (typeof f.email1 != "undefined")
{
if ((f.email1.value == "") && (f.sameAsShip.checked) )
{
customAlert ("email1",bnadd_msg_018);
if ((typeof TeaLeaf != "undefined") && (typeof TeaLeaf.Client != "undefined") && (typeof TeaLeaf.Client.tlAddEvent != "und开发者_开发百科efined") ) {
var nVO = { ErrorMessage : bnadd_msg_018}
TeaLeaf.Event.tlAddCustomEvent(subtype, nVO);
}
return false;
}
//Validate that email address has @ and .
if(f.email1 && ( f.email1.value != "" ) && (!editEmail(f.email1.value,'Email Address')))
{
return false;
}
if(addrType == atBill)
{
if(f.email1.value == "")
{
customAlert ("email1",bnadd_msg_018);
if ((typeof TeaLeaf != "undefined") && (typeof TeaLeaf.Client != "undefined") && (typeof TeaLeaf.Client.tlAddEvent != "undefined") ) {
var nVO = { ErrorMessage : bnadd_msg_018}
TeaLeaf.Event.tlAddCustomEvent(subtype, nVO);
}
return false;
}
else
{
if(f.email1 && ( f.email1.value != "" ) && (!editEmail(f.email1.value,'Email Address')))
{
return false;
}
else
return true;
}
}
}
break;
Working. Thanks for the help on prior questions.
case "email2":
// Checking to make sure email field is on the form
if (typeof f.email2 != "undefined")
{
if ((f.email2.value != f.email1.value) && (f.sameAsShip.checked) )
{
customAlert ("email2",bnadd_msg_005);
if ((typeof TeaLeaf != "undefined") && (typeof TeaLeaf.Client != "undefined") && (typeof TeaLeaf.Client.tlAddEvent != "undefined") ) {
var nVO = { ErrorMessage : bnadd_msg_018}
TeaLeaf.Event.tlAddCustomEvent(subtype, nVO);
}
return false;
}
//Validate that email address has @ and .
if(f.email2 && ( f.email2.value != f.email1.value) && (!editEmail(f.email2.value,'Email Address')))
{
return false;
}
if(addrType == atBill)
{
if(f.email2.value != f.email1.value)
{
customAlert ("email2",bnadd_msg_005);
if ((typeof TeaLeaf != "undefined") && (typeof TeaLeaf.Client != "undefined") && (typeof TeaLeaf.Client.tlAddEvent != "undefined") ) {
var nVO = { ErrorMessage : bnadd_msg_005}
TeaLeaf.Event.tlAddCustomEvent(subtype, nVO);
}
return false;
}
else
{
if(f.email2 && (f.email2.value != f.email1.value) && (!editEmail(f.email1.value,'Email Address')))
{
return false;
}
else
return true;
}
}
}
break;
精彩评论