I'm sorry.  I know you thought that validating an email address is simple, but I'm afraid that you're wrong here.  It's a bit more complicated than y

Your E-Mail Validation Logic is Wrong

submited by
Style Pass
2021-05-24 11:30:03

I'm sorry. I know you thought that validating an email address is simple, but I'm afraid that you're wrong here. It's a bit more complicated than you think. Quite a bit, actually. Allow me to illustrate:

What does an email address look like? For the most part, that's easy, right? We have a username, followed by an @ sign, followed by a domain name and we're done. For example: jschauma@netmeister.org. Simple enough.

Alas, it turns out that it's not that easy. And so to really understand what is valid (even if not necessarily widely accepted) and what is invalid (even if perhaps still accepted by some mail servers), we of course have to go back to the RFCs. We'll start out with RFC5321, and just to be comprehensive, we're strictly looking at the MAIL FROM / RCPT TO SMTP commands, as defined in Section 4.1.2. So let's start:

Most people, when trying to validate an email address, will likely suggest that we can split the address into two parts -- the part that's to the left of the @, and the part to the right. But the RFC actually permits the use of RFC1711 Source Routing. So our first weird-but-valid email address is:

Leave a Comment