I am using the following javascript regex email validate function but it doen’t seem to work why….
function IsValidEmail(email) {
var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
return filter.test(email);
}
function forgetpassword() {
if (document.getElementById("ctl00_TxtEmailId").value == "") {
return false;// this condition gets exected so no prob with my txtboxID
}
if (document.getElementById("ctl00_TxtEmailId").value != "") {
return IsValidEmail(document.getElementById("ctl00_TxtEmailId").value);
}
return true;
}
My failed inputs were test,test@test and also test@test.com
Guys my textbox is within a facebox modal popup…. when i tried alert(document.getElementById("ctl00_TxtEmailId").value with some text jsadf the alert displayed with nothing… Why?
I would change the regexp to something like
and I would rewrite forgetpassword to
Edit: Complete function
IsValidEmail('janus@aaa.bbb') -> truein Chrome / IE8