再次验证电子邮件地址
查看此处有关电子邮件地址验证的帖子,我希望对我正在执行的客户端测试更加自由。
到目前为止我看到的最接近的是:
^([\w-\.]+)@((\[[0–9]{1,3}\.[0–9]{1,3}\.[0–9]{1,3}\.)|(([\w-]+\.)+)) ([a-zA-Z]{2,4}|[0–9]{1,3})(\]?)$
这与此不匹配#[email protected]< /a>,根据 RFC,它是有效的
- 大写和小写英文字母(az、AZ)、
- 数字 0 到 9
- 字符! # $ % & ' * + - / = ? ^ _ ` { | } ~
- 性格。 (点、句点、句号),前提是它不是第一个或最后一个字符,并且也不是连续出现两次或多次。
我想要一个非常简单的匹配:
- 不以 .
- 之前允许的任何字符 @
- @
- 之后允许的任何字符不连续。或@
- 最后一个之后的允许部分。 (tld) 必须是 [a-z0-9-]
我将使用 \i 使搜索不区分大小写。连续的字符是我挂断的地方。
Looking at the posts here for email address validation, I am looking to be much more liberal about the client side test I am performing.
The closest I have seen so far is:
^([\w-\.]+)@((\[[0–9]{1,3}\.[0–9]{1,3}\.[0–9]{1,3}\.)|(([\w-]+\.)+)) ([a-zA-Z]{2,4}|[0–9]{1,3})(\]?)$
That will not match this#[email protected], which according to RFC is valid
- Uppercase and lowercase English letters (a-z, A-Z)
- Digits 0 through 9
- Characters ! # $ % & ' * + - / = ? ^ _ ` { | } ~
- Character . (dot, period, full stop) provided that it is not the first or last character, and provided also that it does not appear two or more times consecutively.
I want a pretty simple match:
- Does not start with .
- Any character allowed up to the @
- Any character allowed after the @
- No consecutive . or @ allowed
- Part after the last . (tld) must be [a-z0-9-]
I will use \i to make the search case insensitive. The consecutive characters is where I am getting hung up on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
如果你想与官方标准匹配,你可以使用
If you want to match against the official standard, you can use
这取决于谁在使用您的应用程序。对于内部应用程序,用户名通常是有效的电子邮件地址。 RFC-822 电子邮件规范的大部分内容描述了电子邮件地址中可能存在的其他字段。例如,Allen Town 是一个非常标准的电子邮件地址,您可以将其输入到您最喜欢的邮件客户端中。但是,对于应用程序,您可能希望在发送电子邮件时将名称添加到电子邮件地址,并且不希望其成为用户地址的一部分。
验证电子邮件地址的最自由的方法是尝试将电子邮件发送到用户提供的任何地址。如果他们收到电子邮件并可以确认,那么它就是一个有效的地址。
It depends on who is using your applications. For internal applications, often a username is a valid email address. Much of the RFC-822 email spec describes additional fields which may be present in an email address. For example, Allen Town , is a pretty standard email address which you might type into your favorite mail client. However, for an application, you may want to be the one adding the name to the email address when you send email, and don't want that to be part of the users address.
The most liberal way of validating an email address is to just attempt to send an email to whatever address the user gives. If they receive the email, and can confirm it, then it's a valid address.
可以在此处找到非常符合 Perl 风格的 RFC822 正则表达式
A very Perl-ish RFC822 compliant regular expression can be found here
以下内容对我来说已经有用了一段时间了。
The following has been useful for me for quite sometime now.
完美的验证正则表达式可能很难匹配,但我已经使用这个正则表达式相当长一段时间了:
最近才更改它以匹配 6 字符 TLD。
Perfect validation regex is probably hard to match, but I've used this one for quite some time:
Only changed it recently to match 6-char TLDs.