Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Email address validation of Top Level Domain

Our QA has filed a bug that says top level domain of the email address cannot be of one character.

[email protected]

I am having a hard time looking into standards. Can somebody confirm if setting top level domain minimum length is a right thing to do?

like image 921
hrishikeshp19 Avatar asked Mar 21 '13 00:03

hrishikeshp19


2 Answers

The rules for validating email addresses are as complicated as they are likely to be buggy in their implementation.

Rather than validating an email address, consider verifying it directly instead: http://davidcel.is/blog/2012/09/06/stop-validating-email-addresses-with-regex/

The problem with your case, is that there is a very real possibility that ICANN might introduce single-letter top-level domain names, and individual DNS labels can be of length 1, in fact "bar.z" is a valid email address domain name if sent from within a DNS tree/organization where that exists as a sub-domain (i.e. if the mailserver is smtp.mycompany.org and I've also defined an MX server for bar.z.mycompany.org).

like image 196
Dai Avatar answered Sep 25 '22 23:09

Dai


Note that I wrote a small C library call libtld for that purpose. It may be useful to you. Note that the amount of data required to support all TLDs, world wide, is quite staggering so I would not implement such in Javascript. That being said, maybe if you can compress the data more... The library also includes a PHP extension so you can use the functions and results directly from PHP.

like image 34
Alexis Wilke Avatar answered Sep 22 '22 23:09

Alexis Wilke