Possible Duplicate:
Validate email address in Javascript?
I'm having some trouble with validating email address client side using Javascript. After a lot of searching I found a regular expression which is as follows:-
/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$
It was working fine with most email ids I have tested with. But suddenly I discovered that it's also saying email's with .com.com like extensions, which is a serious bug for me.
How my question is that how I can modify the mentioned regular expression which will invalid .com.com also.
I should also mention that i have also tried with many other regular expressions but they all seem to have this same mentioned problem...
Thanks...
This will invalidate any address ending in .com.com:
/^([A-Za-z0-9_\-\.])+\@(?![A-Za-z0-9_\-\.]+\.com\.com)([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$
This will also invalidate those ending in @com.com:
/^([A-Za-z0-9_\-\.])+\@(?!(?:[A-Za-z0-9_\-\.]+\.)?com\.com)([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$
Finally, this will invalidate those ending in any repetition, eg, .net.net, .au.au, etc:
/^([A-Za-z0-9_\-\.])+\@(?!(?:[A-Za-z0-9_\-\.]+\.)?([A-Za-z]{2,4})\.\2)([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$
Try this regex:
function verifyEmail(){
var status = false;
var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
if (document.myform.email1.value.search(emailRegEx) == -1) {
alert("Please enter a valid email address.");
}
else{
status = true;
}
return status;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With