简体   繁体   English

JS 上的 email 验证器模式

[英]email validator pattern on JS

So I have a form with email field, and I have a validator function for the form, I moved the function to the script of the page of the form and it gets the '@' char as a comment, what can I do about it?所以我有一个带有 email 字段的表单,并且我有一个用于表单的验证器 function,我将 function 移到了该表单的脚本中?

 $.validator.addMethod("customEmail",
        function (value) {
            return /^([\w-]+((?:\.[\w-]+)*(?:\+[\w-]+)*)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-zA-Z]{2,6}(?:\.[a-zA-Z]{2})?)$/.test(value);
        },
        contactFormInvalidMailError
    );

Try this Regular Expersion: /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.[a-zA-Z]{2,3})$/ First: name before @ is not limited, so use +.试试这个正则表达式: /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.[a-zA-Z]{2,3})$/第一:@前面的名字不限,所以用+。 Domains "com", "org" or "net" have length 3, so add {2, 3}.域“com”、“org”或“net”的长度为 3,因此添加 {2, 3}。 I don't why @ is comment, my regex works for me.我不为什么 @ 是评论,我的正则表达式对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM