最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Email address validation of Top Level Domain - Stack Overflow

programmeradmin0浏览0评论

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?

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?

Share Improve this question edited Feb 2, 2014 at 20:53 unor 96.9k28 gold badges224 silver badges379 bronze badges asked Mar 21, 2013 at 0:32 hrishikeshp19hrishikeshp19 9,03627 gold badges82 silver badges144 bronze badges 4
  • 1 email validation is hard! z and other stuff is valid. – powtac Commented Mar 21, 2013 at 0:34
  • The best way to validate an email address is by sending a verification email. Any other method does not guarantee that the address is valid, merely that it could be valid, and even that is subjective. – Lee Taylor Commented Mar 21, 2013 at 0:38
  • What does the standard say? Does it say that TLD with one character is valid? – hrishikeshp19 Commented Mar 21, 2013 at 0:40
  • 3 @powtac, although I do agree that for an email .z is valid, for a public email it is not. Actually the email address "foo" is valid too as the default domain is localhost so it is equivalent to "foo@localhost". However, 99.999% of the time, someone who thinks "is this email valid?" does discard all local or intranet email addresses because those are well taken care of without special code. – Alexis Wilke Commented May 25, 2013 at 10:05
Add a ment  | 

3 Answers 3

Reset to default 5

The rules for validating email addresses are as plicated 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.mypany and I've also defined an MX server for bar.z.mypany).

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 press the data more... The library also includes a PHP extension so you can use the functions and results directly from PHP.

Up to now, email top level domain's length should locate in [2,6],but it's not a constant stanard because everything is changing. Validate email is very hard, you can't know whether an email address can actually receive email until you try to send email to it, though it fit email formal standard.

发布评论

评论列表(0)

  1. 暂无评论