What is the least bad regex to reject definitely invalid email addresses?

Possible Duplicate:
Validate email address in Javascript?

I know there is no way to validate an email address by using only regex, but I think I should be able to reject some obviously invalid ones in order to help friendly users who by mistake entered something different, such as their name or password into the email address field. So, I do not want to reject any valid email addresses, but would like to reject as many invalid email formats as is possible using only a regex. But I guess any javascript/jquery/... would be ok too.

Here is what I have so far:

^.+@.+..+$

Yes, there is no regex for real validation, but there should be some for rejection. No, this will not prevent anyone from entering fake addresses. Yes, you still have to send a confirmation email to validate for real.

The above regex will be used from javascript.

--

In .NET I would instead let .NET validate the email format using

    try
    {
      var mailAddress = new MailAddress(possibleMailAddress);
    }

and if ok, check the DNS records for the domain part to see if there might be an email server. Only if the DNS records clearly indicate that there can be no email server or if there is no such domain then the email address is rejected. Then cache some of the results in order to speed up future lookups.

Still, I have to send confirmation emails for validation...


官方标准RFC 2822描述了使用此正则表达式的有效电子邮件地址的语法:

(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[x01-x08x0bx0cx0e-x1fx21x23-x5bx5d-x7f]|[x01-x09x0bx0cx0e-x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[x01-x08x0bx0cx0e-x1fx21-x5ax53-x7f]|[x01-x09x0bx0cx0e-x7f])+)])
链接地址: http://www.djcxy.com/p/16520.html

上一篇: 根据RFC5321 / RFC5322对电子邮件地址进行正则表达式验证

下一篇: 什么是拒绝绝对无效的电子邮件地址最不好的正则表达式?