我正在使用以下内容进行电子邮件验证:
var filter = /^([\w]+)(.[\w]+)*@([\w]+)(.[\w]{2,3}){1,2}$/; // For Email Validation
if (filter.test(emailInputVal))) {console.log('good')}
Run Code Online (Sandbox Code Playgroud)
出于某种原因,上述内容不适用于具有子域名的电子邮件任何想法为什么?
xxxx@xxx.xxx.com
Run Code Online (Sandbox Code Playgroud)
谢谢
因为你的正则表达式不正确.试试这个:
var filter = /^\w+(?:\.\w+)*@\w+(?:\.\w+)+$/;
Run Code Online (Sandbox Code Playgroud)
验证电子邮件地址时,此链接可以帮助您
这个符合RFC 2822标准的非平凡简化正则表达式:
var filter = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)\b/;
Run Code Online (Sandbox Code Playgroud)