Jump to content

E-mail Validation not working


zed420

Recommended Posts

Hi All

Can some please tell me what is wrong with my code it keeps giving me the error message even with right Email address. Some help will be greatly appreciated.

if (myform.email.value !=  "/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/"){
alert("Invalid E-mail Address! Please re-enter.");
myform.email.focus();
return (false)
}
return (true);
}

Thanks

Zed

Link to comment
https://forums.phpfreaks.com/topic/133944-e-mail-validation-not-working/
Share on other sites

This doesn't look anything like the way I do regular expressions.

 

Try this URL:

 

http://www.w3schools.com/jsref/jsref_obj_regexp.asp

 

Also, remember you need to use the double equals sign for validation.

 

To expand on this, you (the OP) would want to do something like:

var regex = new RegExp("/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/", "gi");

if(!regex.test(myform.email.value))
{
   alert("Invalid e-mail address!");
   myform.email.focus();
   return false;
}
else
{
   return true;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.