3 ms·
I understand that the first email regex is simplified and as a result doesn't handle oddities such as weird symbols, quotations and IP addresses, but it should
by consto 10y ago
I understand that the first email regex is simplified and as a result doesn't handle oddities such as weird symbols, quotations and IP addresses, but it should be able to handle modern TLDs. Not only do you have names longer than 4 characters, but internationalised domain names starting with --.
https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains https://en.wikipedia.org/wiki/List_of_Internet_top-level_dom...
Depending how simple you want it either:
\b[A-Z0–9._%+-]+@[A-Z0–9.-]+\.(xn--[A-Z0-9]|[A-Z]+)\b
or simpler:
\b[A-Z0–9._%+-]+@[A-Z0–9.-]+\.[A-Z0-9-]+\b
However you could argue that validating email via regex misses the point entirely. A simple, permissive regex is all you really need assuming you are actually sending an email to check that the account exists.
- malka 10y agoUsually, I just check that there is an '@' somewhere in it.
- mioelnir 10y agoIt is things like `net/mail.ParseAddress()` that I have come to really enjoy in Go's standard library.
- Piskvorrr 10y agoYup. If the very first thing I see on a page is "eeeevery valid e-mail ends with \.[A-Z]{2,4}", my impression immediately goes from "this might be interesting" to "canine aviator": https://s-media-cache-ak0.pinimg.com/736x/49/dd/c5/49ddc5c9b9e327b495bb9f7dc06eebb7.jpg https://s-media-cache-ak0.pinimg.com/736x/49/dd/c5/49ddc5c9b...
- savolai 10y agoIf you guys want to help, practical or interesting regex examples are more than welcome for future demos of the UI/product. Thanks! https://pad.riseup.net/p/regexes-you-can-read-samples https://pad.riseup.net/p/regexes-you-can-read-samples -OP/author