[英]Javascript email regex
I've come across a description of a decent email regex. 我遇到过对正则电子邮件正则表达式的描述。
/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
But I would also like to include some punctuation characters into the first part of the email whilst retaining the rest of the functionality (such as no repeated .) 但是我还想在电子邮件的第一部分中包含一些标点符号,同时保留其余功能(例如,不再重复)。
The best I have come up with so far is: 到目前为止,我能想到的最好的是:
([\/!#$%&'*+-=?^_`{|}~]*\w+)([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,40})+$
But this will not allow punctuation at the end of the first part of the email. 但这不允许在电子邮件的第一部分末尾使用标点符号。
I find regex so confusing, does anyone know how to properly implement this? 我发现正则表达式令人困惑,有人知道如何正确实现吗?
Example: 例:
Yes email@domain.com
Yes firstname.lastname@domain.com
Yes email@subdomain.domain.com
Yes firstname+lastname@domain.com
Yes email@123.123.123.123
Yes email@[123.123.123.123]
Yes "email"@domain.com
Yes 1234567890@domain.com
Yes email@domain-one.com
Yes _______@domain.com
Yes email@domain.name
Yes email@domain.co.jp
Yes firstname-lastname@domain.com
No plainaddress
No #@%^%#$@#$@#.com
No @domain.com
No Joe Smith <email@domain.com>
No email@domain@domain.com
No .email@domain.com
No email.@domain.com
No email..email@domain.com
No あいうえお@domain.com
No email@domain.com (Joe Smith)
No email@domain
No email@-domain.com
No email@domain.web
这是我最近的尝试,我认为这是正确的
^[a-zA-Z0-9_!#$%&‘*\=\+\/\?^{|}~]+([\.-]?[a-zA-Z0-9_!#$%&‘*\=\+\/\?^{|}~]+)*@\w+([\.-]?\w+)*(\.\w{2,50})+$
([a-zA-Z0-9\-\_\"]+)([\_\.\-\+{1}])?([a-zA-Z0-9\-\"\_]+)\@([a-zA-Z0-9\[]+)([\-])?([a-zA-Z0-9]+)?([\.])([a-zA-Z0-9\.\]]+)
Jack, the expression I have mentioned above will provide the solution for this problem. 杰克,我上面提到的表达方式将为该问题提供解决方案。 This will give the desired results according to the question.
这将根据问题给出所需的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.