Hello All,
I found out the javascript test function has a strange behaviour in my code.
- I defined a match string variable in the first line of my widget.
var emailPatt=/@(tomtom|stream).com/ig;
- And then i use it in my function
var me=this; alert(emailPatt.test(eo.data.username));
if(emailPatt.test(eo.data.username)) //Search the regualr expres between string { alert("test works"); RightNow.Event.fire("evt_loginFormSubmitRequest", eo); new YAHOO.util.Anim("rn_" + this.instanceID + "Content", { opacity: { to: 0 } }, 0.5, YAHOO.util.Easing.easeOut).animate(); YAHOO.util.Dom.addClass("rn" + this.instanceID, 'rn_ContentLoading');
//since this form is submitted by script, force ie to do auto_complete
if(YAHOO.env.ua.ie > 0)
{
if(window.external && "AutoCompleteSaveForm" in window.external)
{
var form = document.getElementById("rn_" + this.instanceID + "_Form");
if(form)
window.external.AutoCompleteSaveForm(form);
}
}
return false;
}
else if(!emailPatt.test(eo.data.username))
{
alert(emailPatt.test(eo.data.username));
// alert ("not tomtom email address");
me._onLoginResponse("evt_loginFormSubmitResponse", [{
w_id : eo.w_id,
result : 0,
message : RightNow.Interface.getMessage('EMAIL_IS_NOT_VALID_MSG')
}]);
}
},
So, the funny thing is here. The first alert(emailPatt.test(eo.data.username)); return true, the if(emailPatt.test(eo.data.username)) //Search the regualr expres between string return false,
The else if section , return true.
Anyone knows why it happens like that.
Thank you
Regards, Qing