【发布时间】:2012-04-29 10:50:48
【问题描述】:
//if HTML5 input email input is not supported
if(type == 'email'){
if(!Modernizr.inputtypes.email){
var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@([a-zA-Z0-9\-])+\.+([a-zA-Z0-9]{2,4})+$/;
if( !emailRegEx.test(value) ){
this.focus();
formok = false;
errors.push(errorMessages.email + nameUC);
return false;
}
}
}
这是我的 javascript 正则表达式,用于检查电子邮件格式是否正确。但是当我自己尝试时,它不会显示任何 ..@. 的错误。它最终不会检查 .com 或其他任何内容。我究竟做错了什么?
【问题讨论】:
-
我在你的问题标题中闻到了太多的大写字母。这个正则表达式很可怕。有超过 4 个字符的 TLD,
+在电子邮件地址的本地部分完全有效。它在 IDN 上也失败了。
标签: javascript regex email verification email-validation