4 ms·
Don't use a regex, test only for a @ and a dot after it and call it a day. Btw content is unreadable thanks to aggressive adblocker detection so much that this
by tiborsaas 3y ago
Don't use a regex, test only for a @ and a dot after it and call it a day.
Btw content is unreadable thanks to aggressive adblocker detection so much that this feels like spam.
- bazoom42 3y agoEven foo@bar may be a vaild email.
- addandsubtract 3y agoThis is where the linked regex fails at.
- ceejayoz 3y agoOr correctly handles, for most of the use cases you’d want it for. If you’re building a web app, foo@gmailcom is almost certainly a mistake.
- bazoom42 3y agoOf course, since there isn’t a top level domain called gmailcom. But a regex cant tell you that.
- ceejayoz 3y agoGmail doesn't need to support "you own an entire TLD and use its root for email" use cases, so you can at least check for a dot after the @ and catch a bunch of typos that leave frustrated users.
- tiborsaas 3y agoI know about this, but how many domains exists with just a root domain? The vast majority of cases, a missing dot is a typo. I also wouldn't want to imagine how painful using services must be with a foo@bar style address.
- bazoom42 3y agoThe vast majority of common typos result in a syntactically valid email address anyway. A regex is just not an appropriate tool for email validation.
- ceejayoz 3y ago"We can't catch all typos, so we won't catch any" is a silly approach to form validation. I can't check that 123-45-6789 is a valid Social Security Number, but I can still reject "FARTS". The same is true for "foo@gmailcom" for a public-internet facing contact us form.
- bazoom42 3y agoWhy not reject invalid top level domains then? This is going to catch a vastly larger amount of typos (including foo@gmailcom) without eliminating any valid emails.