I am quite amazed that many web-sites fail to allow email addresses of the form x+y@z.domain
.
This is called subaddressing and has been in the email addressing specs since ages.
Do not validate, but send
Basically the only way to verify the validity of an email address is to send an email to it, and wait for it to be accepted or rejected.
Even the best regex will “have almost no false negatives”, which means they will reject valid email addresses.
Further reading
Please read and implement these specs before rejecting email addresses you think might be invalid:
- [WayBack] RFC 5233 – Sieve Email Filtering: Subaddress Extension
- [WayBack] RFC 3696 – Application Techniques for Checking and Transformation of Names
- [WayBack] Mail::RFC822::Address
The RFC allows comments to be arbitrarily nested. A single regular expression cannot cope with this.
- [WayBack] Gmail address with “+” within the recipient name – Web Applications Stack Exchange
any ASCII graphic (printing) character other than the at-sign (“@”), backslash, double quote, comma, or square brackets may appear without quoting.
- [WayBack] [3527] Email addresses with plus sign (+)
Sub-addressing
Some mail services allow a user to append a +tag qualifier to their e-mail address (e.g., joeuser+tag@example.com). The text of tag can be used to apply filtering. The text of the tag can also be used to help a user figure out which organization “leaked” the user’s email address to a spammer. However, some mail servers violate RFC 5322, and the recommendations in RFC 3696, by refusing to send mail addressed to a user on another system merely because the local-part of the address contains the plus sign (+). Users of these systems cannot use plus addressing. On the other hand, most installations of the qmail and Courier Mail Server products support the use of a dash ‘-‘ as a separator within the local-part, such as joeuser-tag@example.com or joeuser-tag-sub-anything-else@example.com. This allows qmail through .qmail-default or .qmail-tag-sub-anything-else files to sort, filter, forward, or run an application based on the tagging system established. Disposable e-mail addresses of this form, using various separators between the base name and the tag are supported by several email services, including Runbox (plus and minus), Google Mail (plus), Yahoo! Mail Plus (minus), and FastMail (plus). The name sub-addressing is the generic term (used for plus-addressing and minus-addressing) found in some IETF standards-track documents, such as RFC 5233.
- [WayBack] How to Find or Validate an Email Address
Regexes Don’t Send Email
Don’t go overboard in trying to eliminate invalid email addresses with your regular expression. The reason is that you don’t really know whether an address is valid until you try to send an email to it. And even that might not be enough. Even if the email arrives in a mailbox, that doesn’t mean somebody still reads that mailbox. If you really need to be sure an email address is valid, you’ll need to send an email to it that contains a code or link for the recipient to perform a second authentication step. And if you’re doing that, then there is little point in using a regex that may reject valid email addresses.
A nice overview of people trying to answer with a regular expression, and comments indicating all those attempts fail in one way or the other is at [WayBack] regex – How to validate an email address in JavaScript? – Stack Overflow
–jeroen