4

I just read an article which states:

Internet domain addresses opened up to wave of new suffixes

Internet naming board approves huge expansion of approved domain extensions with .hotel, .bank, or .sport auctions likely.

Twenty-six years after .com was first unveiled to the world, officials have swept away tight regulations governing website naming, opening up a whole world of personalised web address suffixes.

But... I just learned how to validate email addresses by checking (among others variables) the number of characters used after the dot (i.e., .com, .fr, etc.). What now?

Analysts say they expect 500 to 1,000 domain suffixes, mostly for companies and products looking to stamp their mark on web addresses, but also for cities and generic names such as .bank or .hotel.

Maybe this is not a problem. But how are we going to validate email addresses? What’s the plan?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
sleeper
  • 3,446
  • 7
  • 33
  • 50
  • AFAIK, a valid email address was only ever required to be a string separated by an @ symbol, for example `local@domain`. – Marcel Jun 22 '11 at 10:00
  • The canonical for email validation is *[How can I validate an email address using a regular expression?](https://stackoverflow.com/questions/201323/)* (3,800 upvotes, 122 answers (incl. deleted), and 1.9 million views). Another asks essentially the same question for JavaScript (a regular expression): *[What's the best way to validate an email address in JavaScript?](https://stackoverflow.com/questions/46155/)* – Peter Mortensen Feb 16 '22 at 23:14

5 Answers5

9

IMO, the answer is to screw email validation beyond <anything>@<anything>, and deal with failed delivery attempts and errors in the email address (both of which are going to happen anyway).

Related:

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • 1
    So the vibe I get is "Dont sweat it". Cool. Reading the responses, the only realistic answer was found in your link (and reinforced in the other threads): "Thou shalt send a confirmation e-mail and be done with it!" ...so let it be written, so let it be done! Thanks everyone! – sleeper Jun 22 '11 at 10:19
  • `checkValidity()` is a native way to check that: https://caniuse.com/#search=checkvalidity example: https://jsfiddle.net/sheriffderek/khnp1grq – sheriffderek Jan 15 '20 at 16:35
6

As I've answered elsewhere, this regex is pretty good at handling localization and the new TLDs:

(?!^[.+&'_-]*@.*$)(^[_\w\d+&'-]+(\.[_\w\d+&'-]*)*@[\w\d-]+(\.[\w\d-]+)*\.(([\d]{1,3})|([\w]{2,}))$)

It does validate Jean+François@anydomain.museum and 试@例子.测试.مثال.آزمایشی, but it does not validate weird abuse of those nonalphanumeric characters, for example '.+@you.com'.

TombMedia
  • 1,962
  • 2
  • 22
  • 27
4

Validating email addresses beyond a check for basic, rough syntax is pointless. No matter how good a job you do, you cannot know that an address is valid without sending mail to it and getting an expected reply. The syntax for email addresses is complex and hard to check properly, and turning away a valid email address because your validator is inadequate is a terrible user experience mistake.

Pointy
  • 405,095
  • 59
  • 585
  • 614
3

See What is the best regular expression for validating email addresses?.

It’s with the current TLD's already quite impossible to verify email address using regex (and that’s not the fault of the TLD's). So don't worry about new TLD's.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
stema
  • 90,351
  • 20
  • 107
  • 135
0

The way I see it, the number of TLDs, while much larger than today's, will still be finite and deterministic - so a regex that checks against a complete list of possible domain suffixes (whether that list is your own or, hopefully, provided by a reliable third-party such as ICANN) would do the trick.

chrisfrancis27
  • 4,516
  • 1
  • 24
  • 32
  • You really want to add to your life the task of maintaining either the list or the external dependency on some network service? – Pointy Jun 22 '11 at 10:01
  • Well, personally I wouldn't even bother going beyond checking for the `@` character with some stuff either side, but I try not to factor my own pitiful laziness into answers... :) – chrisfrancis27 Jun 22 '11 at 10:04