34 ms·
Complexities of e-mail validation logic
- arkitaip 6y agoMost of these are just overcomplicating validation. What really matters is account verification, i.e. sending an email to the specified email address in order to verify its authenticity before sending any kind of email (transactional, marketing) to the account. At this point, not doing email verification should be considered a dark pattern because it causes so much trouble when people's email addresses are used without their permission.
- delecti 6y agoAnd "permission" isn't even the only issue. Months of Doordash account emails were lost to the ether because I made a typo (gmail.lcom) in my personal email, and it was basically impossible to change the email on an account (their SMS verification seems broken). It does explain why I never got order confirmations though, that had seemed odd.
- jerf 6y agoIt seems to be a common antipattern for somewhat smaller sites to make the email address the primary key on the account too, and then it's virtually impossible to ever change it after that. As you scale up it becomes impossible to ignore the fact that people change email addresses sometimes, but I've lost track of the number of smaller sites that assume it's a safe primary key.
- cperciva 6y agoraises hand I can confirm that this is a very stupid mistake to make. :-(
- cphoover 6y agoIf your validation function works for 99.99% of your user's email addresses and it's a big unnecessary lift to get that other .01% your logic is not wrong.
- tgv 6y agoI don't think I've seen a bang path since 1990. The claim "Your E-Mail Validation Logic is Wrong" is just pedantry.
- strken 6y agoWhat you've seen since the 80s ended is unfortunately only a subset of all the horrible edge cases your users will run into.
- ok123456 6y agoWhat sendmail rules would you even use in 2021 to process a bang path? Just deny.
- icedchai 6y agoA little later for me. I last used bang paths in 1994, when I had a UUCP feed.
- LinAGKar 6y agoJust get rid of that pointless filtering altogether.
- chrismorgan 6y agoI think the best syntax validation technique for email addresses now is found in the HTML spec: https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address https://html.spec.whatwg.org/multipage/input.html#valid-e-ma.... As they say, this is a wilful violation of RFC 5322, because that’s simultaneously too strict, too vague and too lax to be useful. They give a grammar, and the following regular expression implementing it: /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/ Remember that the web is a platform that lives and breathes this stuff. A lot of thought went into this grammar for valid email addresses. This is a good way of filtering out obviously bad stuff while allowing all realistic and sane inputs. One part of all this that I’m not aware of the situation around is “8. You can put emojis in the local part.” The HTML spec’s validator is all ASCII. It does remind you to punycode the domain labels, but makes no mention of internationalised local parts, and I’ve never learned about non-ASCII local parts or how well they’re supported. I gather they may require the sender to be capable as well as the receiver, whereas internationalised domain names were made compatible with all systems via punycode.
- yjftsjthsd-h 6y ago> while allowing all realistic and sane inputs. Isn't that a way of saying "while disallowing perfectly valid options"?
- jcranmer 6y agoWhat's disallowed are a) IP literal addresses and b) localparts that require quoting. These email addresses are highly likely to break many processing steps anyways; I've only ever seen category b in sendmail configs (it can be useful for internal email rerouting purposes). There's a distinction to be drawn between the requirements of the actual MTA/MUA/MSA layers and user applications built on top of them. For the latter, considering emails to be invalid if they contain IP literals or quoted localparts is going to be more helpful than harmful (there's less scope for vulnerabilities in doing so). It's just like assuming email addresses are case insensitive: it's inappropriate if you're an MTA, but for everybody else, go ahead and assume they are.
- StavrosK 6y agoI gave a presentation on this topic in FOSDEM a few years ago: https://www.youtube.com/watch?v=xxX81WmXjPg https://www.youtube.com/watch?v=xxX81WmXjPg (Loudness warning)
- anttisalmela 6y agoIt doesn't really hurt if some more exotic email addresses are not accepted, no one can really use them anyway.
- asddubs 6y agoin fact it probably catches more mistakes than deliberate weird email addresses to be stricter than the standard mandates
- jiofih 6y agoWell, you can’t use them because of attitude like yours. You’re not only annoying those of us who want to use plus signs or international domains, but ensuring the “exotic” half of the world that doesn’t use the Latin alphabet is kinda left out.
- anttisalmela 6y agoNon-ascii alphabets need a lot more support than just accepting them. But I wouldn't really consider plus signs exotic anyway.
- jiofih 6y agoWhat does that even mean? We shouldn’t support them because it requires more work?
- deleted 6y ago[deleted]
- abrowne 6y agoIf you are consistent. A couple times I've successfully signed up for something with a username+string@gmail.com address but then have been unable to unsubscribe because my address is "invalid".
- NullPrefix 6y agoI kinda recall a lawsuit many years ago about a unsubscribe confirmation email.
- buro9 6y agoI have a tld that was recently created (2014) and I still cannot use it in an email address reliably. The domain in question being david.kitchen, so an email may be email@david.kitchen The issue I encounter more than any other is trivial: Most sites still have a tld validation that only accepts domains that end in net|com|org and some other small list of accepted suffixes such as co.uk The list of TLDs is constantly expanding https://newgtlds.icann.org/en/program-status/sunrise-claims-periods https://newgtlds.icann.org/en/program-status/sunrise-claims-... so even `[a-z0-9.-]+@[a-z0-9.-]+\.[a-z0-9]+` would be better than what I see in the wild.
- vidarh 6y agoI was involved in setting up .name back in 2001. We spent ages contacting people with validation rules based on the old set of TLDs. Given that was the first expansion of the gTLD space in a long time, it wasn't so unreasonable then. But it's just astounding that it's still and issue 20 years later.
- znpy 6y agoand the regex you provide doesn't even account for unicode..
- buro9 6y agoThe regex came from the article, and lack of unicode is addressed in the article.
- 6y ago
- schwinn140 6y agoLink is just hanging. Also, anyone notice the OP posts the same couple of posts constantly?
- u801e 6y agoI provide my email address with the +companyname suffix on the local part as a way to filter my email into various folders based on the To header contents. Unfortunately, many websites are configured to reject email addresses that contain a plus character. I've also encountered websites in the past that did accept the + character when creating the account where the email address serves as the user name, but then could not log in because their log in form rejected the + character in the user name.
- fullstop 6y agoAges ago, back in myspace days, their system would permit + when creating an account, but could not handle this in their forgot password / password reset system. I never was able to delete my account because of this.
- inopinatus 6y agoSony's SEN used to have an account creation page that would permit +, but subsequent sign-in interpreted it as a URL-encoded whitespace. No login for you
- ezekg 6y agolol you should have tried to enter a URL-encoded plus sign, %2B.
- torstenvl 6y agoAll social media accounts are delectable on a long enough timescale.
- fullstop 6y agoAs it happens, it was eventually done for me: https://mashable.com/article/myspace-data-loss/ https://mashable.com/article/myspace-data-loss/
- innocenat 6y ago
- burke 6y agoI’ve never seen much point in trying to do better than .+@.+, unless you’re going to pull out the (gargantuan!) authoritative version for some reason.
- michaelt 6y agoToo many sites refuse to let me register as "><script>alert("XSS");</script>@example.com The oppression must end!
- SAI_Peregrinus 6y agoI think the mismatched quotes actually do make that one invalid.
- mro_name 6y agoshouldn't is read Bobby Tables rather than a mere XSS?
- Avamander 6y agoHonestly if that'd ever work, the website has bigger problems anyways.
- kevinmchugh 6y agoImplementing the authoritative version is a waste since you'll also need to keep an up-to-date list of TLDs, and more importantly, you might have a typo in the input that gives a valid-but-incorrect email. After doing your simple regex, the best move is to just send a verification email and wait for the user to click the link, if you really need to be sure.
- wffurr 6y agoYeah, do simple validation, and then just send an email. Even a validated email can still be non-deliverable if there’sa typo in the domain or the first portion.
- dkersten 6y ago
- user3939382 6y agoTFA won’t load for me, but I’d like to make a short PSA: RFC 5322. Lookin’ at you, Walgreens.
- Wronnay 6y agohttps://web.archive.org/web/20210408080002/https://www.netmeister.org/blog/email.html https://web.archive.org/web/20210408080002/https://www.netme...
- deleted 6y ago[deleted]
- ericcholis 6y agoIn addition to a very simple regex, you can do some light verification on DNS and SMTP - nslookup –type=mx email.com - pick the highest priority MX server - telnet mx1.email.com 25 - validate SMTP handshake - Start a connection: EHLO email.com - mail from:<sender@youremail.com> - rcpt to:<recipient@email.com> Obviously, this might be outside the capabilities of some hosts or users. There's a bunch of services that expose this workflow for you as an api. (https://trumail.io/ https://trumail.io/, for example)
- teh_klev 6y agoSee point 10 in the article: "The domain name does not need to resolve" Also the mail server may be temporarily offline or unreachable.
- deleted 6y ago[deleted]
- jusssi 6y agoNon-resolving or offline mail servers count to your bounce rate if you have a 3rd party service handling your outgoing mail. So for that purpose, it is an invalid address in the sense that you should avoid sending anything to it.
- teh_klev 6y agoThose are rules made up for the convenience of marketers and have nothing to do with the technical aspects of mail delivery as defined in the RFCs. Edit just to clarify: KPI's such as bounce rates etc aren't a function of how mail is delivered (RFC5321). These are KPI's collected and collated by non-SMTP applications sitting on top of SMTP infrastructure monitoring bounces. Nowhere in RFC5321 does it mention that a mail server should or must not delivery mail in respect of bounce rates. These are operator defined metrics outside of the scope of RFC5321, that may be aided by additional software or services such as spam detection.
- 6y ago
- csours 6y agoThis feels like a discussion for backend implementations/email forwarders, not for email signups... but hey while this has some attention - For god's sake, put a button that says "This ain't me", at least for important stuff. I'm sorry, but I just can't bring in Clyde's truck for the oil change, cause Clyde ain't me! I also cannot attend Cassidy's parent teacher conference, apologies, I am not in Ohio.
- cratermoon 6y ago>This feels like a discussion for backend implementations/email forwarders, not for email signups... And yet I've worked multiple places where product people asked for "simple email validation" on user signup. If they insist, I ask them to provide some actual test cases that they care about. Sometimes the product folks can be convinced to drop the validation requirement if they can be shown that anyone who can't sign up because their email address doesn't validate will simply move on and not sign up. In the case where your product is B2B and all the employees of your customers are users (say an HR product), then the first time a VIP at an important customer complains, that's usually enough to convince your stakeholders to disable the email validation.
- Yaina 6y agoWhat this article really showed me that this RFC is actually pretty harmful. Supporting all of the rules outlined in the spec is probably a huge burden for maintainers of mail clients and servers. Obviously some parts of the spec are going to be omitted. It's hard to blame them for it, but the same person that rightfully skipped over implementing the routing thingy might've also wrongfully assumed there won't be a Japanese character in the address. And that's what's so bad. You might introduce more issues in your system, by taking the full spec into consideration for your validation, instead of using the whatwg regex someone posted here.
- nradov 6y agoWell if there are problems with the RFC then you should work with the IETF to correct those. They have an open standards development process.
- awestroke 6y agoAnother option is to just ignore the RFC
- forgetfulness 6y agoThat does mean that there will only be an ad-hoc undocumented standard for email addresses, rather than one that's serviceable. Web application validation forms add a different layer to the standard and are sort of hard to tame; anyone can push together a few lines of PHP or Javascript code and conjure their own email address standard out of thin air.
- gifnamething 6y agoWill be? There is an ad-hoc standard. If the standard fails to be used, the standard is defective.
- numpad0 6y agoIsn’t it just not very nice to ignore a Request for Comments
- _wldu 6y agoPerfect is the enemy of good. If it is a string that has an @ sign, a dot and is at least six characters long, it's probably a valid email address. a@b.cc No need to go further than this. It's not worth the time.
- criddell 6y agoYou don't need the dot. Item 12 in the list is "You can have dotless domain names."
- Biganon 6y agoDo you know many people who own a TLD?
- criddell 6y agoLast time I checked, some of the TLDs did have an MX record. Perhaps they use it for support or something? I could imagine emailing info@tld or admin@tld or support@tld.
- harg 6y agoindeed, the point the parent comment was making is that effective email validation need not perfectly implement the RFC. dotless domains are going to be so rare in practice (unless your project has some niche use-case) that you can probably ignore them and call them invalid for the sake of simplicity.
- criddell 6y agoIt's worth alerting the user that they likely made a mistake. However, I think they should be allowed to continue with a dotless address.
- biztos 6y agoThis is a great run-down of the trouble with e-mail addresses. I worked in e-mail security for quite a while. "Write an e-mail address parser" was my go-to technical interview question. It was pretty easy to see if the candidate had ever given any real thought to e-mail (most had not); and you could also pick up a lot of signals about engineering style, for instance if they started with a regex (fewer did than I expected). And it was trivial to adjust the difficulty: if someone thought the question was easy and had a fast solution, you could just throw them a test-case like the ones in this article. (Note: the actual title is "Your E-Mail Validation Logic is Wrong" -- and it's only about addresses, the author isn't implying that e-mail systems can't validate messages nor for that matter addresses.)
- LambdaComplex 6y agoWhat if the answer they gave was "This is a very hard problem that honestly isn't worth solving, just check against a .@. regex and call it a day?"
- mrunkel 6y agoSo only a@b? I think you’re missing some stuff in your regex.
- AnIdiotOnTheNet 6y agoEh, that's why you use a validation email. Only bother with 'validation' at all to catch something obviously wrong.
- deleted 6y ago[deleted]
- gvx 6y agoHN markup strikes again (OP wrote .X@.X, where X is an actual asterisk, which HN renders as .<i>@.</i>)!
- CydeWeys 6y ago"Can you write me a parser that has a <1% false negative and <1% false positive rate on real email addresses?" A similar enough issue happens in coding interviews anyway. Sometimes the interviewee is aware of a library that essentially solves the problem for you. In those cases I give them some credit for knowing of it and then ask them to implement it anyway, as if the library didn't exist (because there are a large number of problems out there for which a solution doesn't yet exist, and when hiring a SWE you need to find someone who can write new solutions from scratch for those situations; whether a given toy interview problem is such a situation doesn't matter for the purpose of evaluating said skills).
- LogicX 6y agoNice article. My only technical nit would be the statement “if there was an MX record”. Many systems will fall back to an A record to attempt delivery in absence of a MX record.
- high_byte 6y ago"How to Hack Things with These 13 Simple Tricks"
- duckfang 6y agoEmail validation : Accept email from user. Send email to that address with a link to verify. Go/no-go test if link is clicked. (If you're doing some fever garbage or otherwise trying to parse it, you're doing it wrong.)
- swiley 6y agoThis doesn't work with hotmail where sometimes a robot will click the link but refuse to deliver the mail.
- hutrdvnj 6y agoThere is no point in many cases. Even if you can verify that the email address is syntactically valid, you'll still need to check that it was not mistyped, and that it actually goes to the person you think it does. The only way to do that is to send them an email and have them click a link to verify. However, if you still want to validate an email address then use a library. All popular programming languages have email validation libraries. Yes, it's an extra dependency if it's not included in the std lib or the framework you use, but email validation is wrong in 99% of the cases, if you wrote it yourself.
- yawaramin 6y agoOr use the browser. HTML form validation has <input type="email"> which checks that the entry is a valid email address.
- mikl 6y agoNot quite, browsers have slightly different implementations here, we recently had to stop using this because we had customers using IDN e-mails like hansi@lübeck.de and this would fail validation in some browsers (but not others).
- yawaramin 5y agoInteresting. Got a bug report I can track for those browsers?
- ds 6y agoIf your email is <RFC>fan 69™@root I am not going to let you signup. Sending emails cost money and bouncing emails affects your sender reputation. Also, for every user out there using <RFC>fan 69™@root as their email address, there is going to be thousands of people accidently entering their email address incorrectly and not getting a alert about it. Yes you could do fancy shit like checking mx records and whatnot, but come on- Im not going to maintain/build that infrastructure for the one out of a million people who are trying to use that address. Developer time is precious at a startup and supporting <RFC>fan 69™@root while still denying b ob@gmailcom is very, very far down the list of things to do. In summary: I don't suggest doing 'perfect' email validation to RFC spec. You will save money/devtime and make more of your users happy by not doing it.
- josephcsible 6y agoThis logic is why so many Web sites today won't let you use a plus sign in email addresses, which ruins a really nice Gmail feature.
- kyrra 6y agoAs people said, true spammers know to just strip off the "+" in the email address. This is actually a fun reason to set up your own domain and set up email forwarding for *@example.com to go to your main gmail or whatever account, then the "username" part of the email I just set to the domain of the account I'm signing up for. So I'll use amazon@example.com when signing up at Amazon (or whatever site).
- judge2020 6y agoNote that you should only do this for maybe 6-18 characters, some sites will test send an email to [30-100 character random string]@example.com and see if it bounces - if it doesn't, it'll suspect that domain to be some spammer with a catch-all email inbox and block it.
- alufers 6y ago
- fencepost 6y agoHah, even beyond the question of address format variations there are also commercial services that do some level of email address validation - and one of them regards my business email address as invalid (firstname@companyname.com) - adding another letter works, adding punctuation works, it's just my specific first name. Unfortunately it's done via black box on their server(s), so it's not like I can even dig through the code and figure out what's going wrong.
- bcrl 6y agoI think the best email address I ever knew of was n@ai . Unfortunately, the .ai TLD eventually decided it wasn't a good idea to have an MX recorded resolving on the TLD.
- arkitaip 6y agoIt's cute but doomed to fail because it goes against everything most people understand about email addresses.
- mLuby 6y agoValidation errors are common, but warnings are not. I'd like to see more of "Patterns like [what you entered] are uncommon—are you sure?" instead of "Patterns like [what you entered] are not allowed—change it to proceed."
- richeyryan 6y agoI recently implemented this using the great Mailcheck library. So if someone types "gnail.com" or "gmail.con" it detects it and we can show "Did you mean gmail.com?". If someone ignores the suggestion, fair enough. If someone purposely wants to give us a junk email, fair enough. At least we're not frustrating them needlessly. https://github.com/mailcheck/mailcheck https://github.com/mailcheck/mailcheck
- zzo38computer 6y agoMostly, yes. However, some things should probably still be prohibited, such as: - An email address ending with ".invalid", unless invalid email addresses are supposed to be allowed (which in some cases is useful, but you can then disable sending email to such an address, using it only for identification). (I do use such an email address for identification on NNTP.) - Email addresses without at least one at sign. - Email addresses containing control characters (at least ASCII control characters). - If the domain name does not resolve or resolves to a loopback address or LAN address (except for some specialized cases where such a thing is desirable). The same is true for literal IP addresses; if it is a loopback or LAN address then it should be disallowed, but otherwise it can be allowed.
- mooreds 6y agoHah, just went over the email address validation logic in our app last week because a client asked. Turns out we do minimal validation (make sure there is a local and a domain, that there are not two periods next to each other, and a few other things) but what we really rely on is deliverability. In other words, if your email needs to be verified, we'll try to send an email to the address you provide. If the link is clicked (or the code entered), that's good enough for us. Applications using our service (we're an auth provider) can decide for themselves if they need email address validation. It's a boolean flag on the user object. If they do, they can use the functionality we provide to ensure it.
- k__ 6y agoMy main email, which is only 8 characters long, got denied sometimes based on length. Doesn't happen very often, though.
- cratermoon 6y agoI've decided that the best way to validate email address is to not validate them, but require that any signup be finalized by the individual following a link emailed to them. This allows a person to use any damn thing they want as their email address, provided it works and they can get the email.
- welder 6y agoIf sending emails is 100% free, but you still have to worry about your sender reputation. [1] Sending a large amount of mail to invalid emails will start getting your emails put in people's spam folders. That's the reason email validation services exist, to prevent sending to invalid emails. [2] Also, humans make mistakes. You should detect spelling errors and typos then suggest corrections. [3] [1] https://www.mailjet.com/blog/news/3-factors-that-impact-your-ip-reputation/ https://www.mailjet.com/blog/news/3-factors-that-impact-your...] [2] https://www.mailgun.com/email-validation/ https://www.mailgun.com/email-validation/ [3] https://www.npmjs.com/package/mailcheck https://www.npmjs.com/package/mailcheck
- mro_name 6y agoEven if 0% free you'll have to do the opt-in anyway, or how on earth will you figure out if the recipient wants your email? It's hard to be smart with something like names.
- eli 6y agoMickey@mouse.com is a perfectly valid address but it isn’t my address. If that matters for your application you need to spend the capital to send an email. No way around it.
- bobthecowboy 6y agoEven worse, I have commonfirstnamecommonlastname@gmail.com and get several emails a day that I didn't sign up for. Now the person who did sign up isn't getting them and I have to figure out how to opt out of them. Sometimes these website accounts already have payment/personal details associated with them, which I now have access to (and indeed, sometimes have to view) in order to find the "stop sending me email" button. Always send the confirmation "did you sign up?" email. Always.
- xyst 6y agog-mail smtp is returning this error: "Verify that you have addressed this message correctly. Check your SMTP server settings in Mail preferences and verify any advanced settings with your system administrator. The server response was: The recipient address <'*+-/=?^_`{|}~#$@[ipv6:2001:470:30:84:e276:63ff:fe72:3900]> is not a valid RFC-5321 address. <...> - gsmtp" Not even Google engineers can get it right. We are doomed.
- aeharding 6y agoI just want my .dev email address to not be rejected.
- pmontra 6y agoI just check that the string contains at least an @ character. That ensures that we're not rejecting people with uncommon patterns in their email address and takes very little time to design, develop and test. In a project we're doing something fancier: we check the result of sending mail and store it in the database record for the account (Mandrill notifies us on a webhook.) Then we might take actions for bouncing addresses. The actual impact on the project has been zero so far.
- dokem 6y agoSorry no, your email address is wrong. Make a new one.
- slifin 6y agoThere's a lot of busy work in computing in the name of preventing mistakes At a certain level of complexity it's easier to just let mistakes happen and provide correction tools if & when required I remember getting our IPs blacklisted trying to programmatically ask email servers if the email address we were provided was real
- JoyfulPanda 6y agoThere is is awesome talk about E-Mail by Ricardo Signes: https://www.youtube.com/watch?v=JENdgiAPD6c https://www.youtube.com/watch?v=JENdgiAPD6c The first 5 minutes are perl specific, but the rest is email and just hilarious.
- mro_name 6y agoActually email validation is simple: do the opt-in. If confirmed, it's valid.
- deleted 6y ago[deleted]
- mfbx9da4 6y agoI once had a crack at building a sensible email validation library. * Validate the string contains "@" and a "." to the right of it. * Validate common typos * Validate disposable emails * Validate MX records * Validate SMTP server and mailbox https://github.com/mfbx9da4/deep-email-validator https://github.com/mfbx9da4/deep-email-validator I don't have the time to keep it maintained but it works for the most part!
- devfatigue 6y agoWhat if we flipped email validation around and made the users email a one time code to validate their email?
- danrl 6y agoI have a very short email address in the format a@b.tld and for my special friends that don't know how to validate correctly I have created abc@ur-email-validation-is-broken.b.tld I need to use the latter ~5% of the time. Most often I take my business to someone else for the sake of principle.
- deleted 6y ago[deleted]
- jacobobryant 6y agoI just outsource this to Mailgun. User signs up, I send them a confirmation email, account doesn't get created till they click the link. If the email address is invalid, Mailgun returns an error and I show a page that says "We couldn't send an email to <address>. If you're sure that's a valid address, please try again." (Also use recaptcha for bot detection).
- wyldfire 6y ago> The local part is case-sensitive. This seems more like a bug than a feature. Maybe in 1983 the average email user knew what DNS was and could be expected to know one part of the email address would be case sensitive and the other not. But email RFCs are probably like any other RFCs out there and specify existing behavior for the sake of interoperability.
- deckard1 6y agoyeah, and that's a hill I'm willing to die on. Imagine the average non-technical person talking to some customer service agent on the phone and having to figure out if her email is JANEWATSON@gmail.com, JaneWatson@gmail.com, janewatson@gmail.com, or Janewatson@gmail.com. Could you imagine the horror and complete security nightmare of multiple people running around using the same gmail address with different case. Those Jane email addresses above would be four different people. We'd be receiving mail intended for other people all day long.
- eldenbishop 6y agoIt's not even about crazy emails. My wife works for an Aerospace company so her work email was blahblah@blah.aero and a huge number of websites still don't recognize that as a valid top level domain.
- slavik81 6y agoI created myusername@hotmail.com in 1999, then immediately lost the password. I couldn't recover my account or use the same name again, so I created myusername_@hotmail.com. In the twenty-two years that have followed, the only website that has had a problem with my email address is Chapters Indigo, which explicitly rejects it as invalid. For email validation, keeping it simple is best.
- BenjiWiebe 6y agoWhy not accept absolutely anything in the email address field, and just require an emailed link to be clicked before marking the email as validated?
- rblatz 6y agoBecause it causes conversion drop off.
- zzo38computer 6y agoI cannot send a message to the email address they provide, but not because of anything wrong with the email address itself, but because that email address is version 6 internet, and I have version 4 internet.
- eli 6y agoNo the problem is developers confusing validation with verification. You can’t validate your way to a correct address and it’s wrong to try. If your goal is to catch typos you’re better off with very lax validation plus a library that suggests corrections like “gmail.com” for “gnail.com” (both of which are of course technically valid domains)
- permo-w 6y agoI think the author is stretching the words "valid" and "invalid" past their limits here for the sake of hooking you into the article. Yeah, in some countries it's a valid social practice to spit on the floor in public, but in most, it's not. let's say I'm a dev at google, and I'm writing some aspect of gmail. Is !"£$%@gmail.com a valid email? No. So the word valid is clearly not being used correctly here. At the core of smtp these emails are allowed, but in practice they almost never are, and so the opposite is true. All the cases he described are, in practice, invalid.
- crystaln 6y agoSo <any chars>@<any chars> seems beyond good enough. There is no benefit to validating beyond that for almost all cases.
- grouphugs 6y agoit's 2021, i am too poor to make a yahoo email account
- quercusa 6y agoThese days, I think 80% of email validation is just catching 'gmial.com'
- mk81 6y agoClicked thinking this might be useful information; was mostly disappointed.
- sparrc 6y agoI have my own custom email domain (sparr.email) that fails validation surprisingly often.
- saurik 6y agoThis is all a massive misunderstanding. An email address is the local name and the host; a host can't contain an @, so the only thing you frankly need do is split on "last @" and demand the user not escape anything. As for validation, go ahead and try to resolve the domain to make sure it works (and, if you want to verify the local part, do an online check with their server). If this squicks you for some reason--as maybe that format is non-obvious with respect to the lack of a need to escape @--give the user two boxes with a hardcoded @ between them and have them type the two parts separately: pre-parsed input need not ever be escaped, as you aren't going to parse it at all; no need to implement " dequoting. All of these escaping rules are then to support embedding this identifier into SMTP. The rules for embedding the same identifier into MIME are different... and even more complex! In MIME they support random stuff like "comments" in the middle of the string... is that part of the email address identifier? No. An email address simply is not defined by the format you use to send it as part of an SMTP command, nor is it defined by the format you use to send it as part of a MIME message header :/. Into is an identifier that exists separately from either of those two (different) protocols and one would expect any number of ways to escape that content. To demonstrate how ridiculous this all is, imagine someone comes up with a JSON protocol for mail submission and then documents how email addresses now should use \u encoding and escape quotation marks... does that mean users should type that into your app? No. Hell: your email address form is taking an email address and then sending it over HTTP... the escaping rules for HTML form fields are different still, yet no one is asking users to type HTML-escaped strings into other applications, right? The core thing wrong then with your email validation is that you are simply validating the wrong thing: unless you are developing an SMTP server, the rules for how to escape and parse escaped email addresses in RFC5321 are irrelevant; and, likewise, unless you are developing a MIME parser, the rules for how to escape and parse escaped email addresses in RFC5322 are also irrelevant. The only thing that matters from either of these specifications is the underlying basic rule for what semantically can exist in a hostname and a localpart, and RFC5321 is extremely lax: you can use any "ASCII graphic or space", and so excludes only ASCII control characters and 8-bit characters... and then, as mentioned, another RFC removes the 7-bit limitation and opens up the world of Unicode. (To push on it even further: it isn't even clear to me that one should consider the ASCII control character limitation to be fundamental to the email address identifier or a weird limitation of the current version of SMTP; and since none of those email addresses are going to work, I think one may as well just consider the local part to be any string of Unicode code points.) Think about this: it is up to your SMTP library to correctly escape the email address you give it for SMTP, and here's the fun part: if you give it a pre-escaped email address, then clearly it is going to have to double escape it, right? So, semantically, these extended discussions of quoted strings and character limitations are always just so ridiculous :/... you absolutely should not be dealing in SMTP-escaped addresses or asking your user to understand SMTP (and the same goes for MIME). (BTW, if you want some "real hell", one of these two protocols--I forgot which... I presume SMTP--seriously supports an empty local part. If that doesn't tell you everything you need to know about un-opinionated these RFCs are with respect to "anything goes" then I don't know what will ;P.)
- roachpepe 6y agoNot really an email issue so sorry if maybe somewhat off topic but on the subject of validation I can't not bring this up - this, remember the guy whose name was Null? https://www.wired.com/2015/11/null/ https://www.wired.com/2015/11/null/
- sneak 6y agoThis is a bunch of weird edge cases that nobody uses in real life except maybe the plus trick. American Express and Walgreens don't let you set a whatever@whatever.email address because they check for a TLD known at the time of their app's validation code, or something.
- flerchin 6y agoThe one I see over and over is failing to trim the email before doing validation. This is especially egregious at account creation where you want no friction. Users enter their email with their smartphone, and it may append a space at the end. More than once, I've had a relative call me trying to figure out why $website wouldn't accept their email as valid.
- bilater 6y agoUnpopular opinion: Just ignore these edge cases and focus on the 99.99% of the sane population that doesn't get off on having a weird email address. More generally: If an edge case exists and has nothing to do with accessibility (it was caused by a user having a different workflow like needing a screen reader or being in a less developed part of the world with slow internet) then you should dismiss them and not make your code/life unnecessarily complicated.
- jillesvangurp 6y agoThe only relevant email validation is verifying a user can click on a link or enter some code sent to them to the address specified by them. Without verifying ownership, the email address is worthless as an identifier so making it conform to some syntax is not that relevant and you should not use unverified email addresses as identifiers (identity theft is a thing). Obsessing about regular expressions for these addresses is generally a waste of time except for maybe preventing a lot of failed attempts to send stuff to a clearly invalid email address. A simple string contains '@' is probably good enough for that. Worst case the email address does not work and you discard the entered information after some reasonable time frame. The user has the option to try again and do a better job of typing their email address.
- tehwebguy 6y agoCan't seem to find it anymore but wasn't there a post about how the letter "d" by itself was a valid email address at one point?
- radicalriddler 6y agoI have two things. The amount of times I've tried to sign up with my protonmail account to a service and it doesn't pass validation simply because it's a protonmail account (not a gmail, outlook, hotmail or aol apparently). makes me wish everyone did follow the RFC. I actually emailed a service one time, and they responded that it's due to protonmail usually being associated with shady stuff wtf. The second. I had to implement an email validator at one of my previous jobs, and fell down the RFC rabbit hole. Not only did I have to follow the RFC as per my bosses request, but I also had make sure that Amazon SES allowed it. Came out of the office wanting to just walk out onto the road. The weird things that not only email servers allow, but also, what do email clients allow.
- lilyball 6y agoI’m of the opinion that all you should validate is that there is an @, the text to the right side (of the final @) is a well-formed dotted DNS domain, and that there exists at least one (non-whitespace) character to the left of the (final) @. Yes, I can craft garbage emails that pass this quite easily, but who cares? If I’m crafting fake emails I can make valid ones too. This rule ensures I typed the @ and the dot in my domain (we really don’t need to support dotless email domains and it’s better to catch “foo@gmailcom”) and it won’t reject all the weird random emails people might have.
- jedberg 6y agoThere is exactly one right way to validate an email address: Send an email to it. It makes a lot of sense to have a good regex that validates it on the frontend and even tells the user, "hey, this doesn't look valid, are you sure?" but don't ever reject someone for failing your regex. At the end of the day, you should only validate by having them click on a link in their email. Then you know the whole thing works. If you're worried about someone hurting your reputation with a bunch of bad email addresses, you can certainly mitigate that by rate limiting your signup API or even deprioritizing sending confirmation emails to email addresses that don't look valid. But you still should eventually send an email to make sure it's valid and not reject it until it bounces back.
- mikl 6y agoPeople love to quote the RFCs, digging up examples of weird things that are technically allowed in e-mail addresses, but not widely used or supported. Frankly, I don’t give a damn about supporting some l33t h4x0r wanting to be clever about his e-mail address. So no, my logic is not wrong. It just doesn’t care about all the weird edge cases.
- wildmanx 6y agoI'm always amazed by those "you're doing Xyz validation wrong" posts. This is 2021. There should be libs out there that do this perfectly and we should be using those. Nobody should be writing this kind of thing from scratch, especially not somebody with "precious developer time at a startup". For fun, sure, why not. But doing this from scratch for production software is nonsense. Parsing email adresses, URLs, IPs, OS path names, even parsing common file formats, stack frames or, god forbid, hacking your own crypto. Don't.