TLD 可能有多长?

发布于 2025-01-04 18:13:37 字数 91 浏览 0 评论 0原文

我正在 PHP 中开发电子邮件验证正则表达式,我需要知道 TLD 可能持续多长时间并且仍然有效。我做了一些搜索,但找不到有关该主题的太多信息。那么 TLD 可能有多长?

I'm working on an email validation regex in PHP and I need to know how long the TLD could possibly be and still be valid. I did a few searches but couldn't find much information on the topic. So how long can a TLD possibly be?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

踏月而来 2025-01-11 18:13:37

DNS 允许单个标签最多使用 63 个字符。

DNS allows for a maximum of 63 characters for an individual label.

未蓝澄海的烟 2025-01-11 18:13:37

目前存在的最长 TLD 为 24 个字符,并且可能会发生变化。 RFC 1034 指定的最大 TLD 长度为 63 个八位字节。

要获取最长的现有 TLD 的长度:

wget -qO - http://data.iana.org/TLD/tlds-alpha-by-domain.txt | tail -n+2 | wc -L

该命令的作用如下:

  1. 获取 来自 IANA 的实际现有 TLD 的最新列表
  2. 删除第一行,其中是一个很长的评论
  3. Launch wc 计算最长的行

使用 curl 的替代方案感谢 Stefan:

curl -s http://data.iana.org/TLD/tlds-alpha-by-domain.txt | tail -n+2 | wc -L

The longest TLD currently in existence is 24 characters long, and subject to change. The maximum TLD length specified by RFC 1034 is 63 octets.

To get the length of the longest existing TLD:

wget -qO - http://data.iana.org/TLD/tlds-alpha-by-domain.txt | tail -n+2 | wc -L

Here's what that command does:

  1. Get the latest list of actual existing TLDs from IANA
  2. Strip the first line, which is a long-ish comment
  3. Launch wc to count the longest line

Alternative using curl thanks to Stefan:

curl -s http://data.iana.org/TLD/tlds-alpha-by-domain.txt | tail -n+2 | wc -L
寂寞美少年 2025-01-11 18:13:37

-编辑-

根据 RFC 2606 .localhost 是保留域名,其长度为 9 个字符。
这是我所知道的最长的了。

-编辑结束-

但是,我认为您应该关心电子邮件地址长度而不仅仅是 TLD 长度。
以下是这篇文章的引用。
电子邮件地址长度为 254 个字符:

对于最大有效电子邮件地址大小似乎存在一些混淆。大多数人认为它是 320 个字符(用户名 64 个字符 + 域名 255 个字符 + @ 符号 1 个字符)。其他来源建议 129 (64 + 1 + 64) 或 384 (128+1+255,假设用户名未来长度加倍)。

这种混乱意味着您应该注意“稳健性原则”(“开发人员应该仔细编写严格遵守现有 RFC 的软件,但接受和解析来自可能与这些 RFC 不一致的同行的输入。” - 维基百科)在编写处理电子邮件地址的软件时。此外,某些软件可能会因天真的假设而瘫痪,例如认为 50 个字符就足够了(示例)。您的 200 个字符的电子邮件地址在技术上可能是有效的,但如果大多数网站或应用程序拒绝它,这对您没有帮助。

当前电子邮件的实际最大长度为 254 个字符:

<块引用>

RFC 3696 的原始版本确实说 320 是最大长度,但是 John Klensin (ICANN) 随后承认这是错误的。”

<块引用>

“这是由域的最大长度(255 个字符)+ 邮箱的最大长度(64 个字符)+ @ 符号 = 320 个字符的简单算术得出的。错误的。这个谣言实际上记录在原始版本中RFC3696 中已更正。勘误表实际上 RFC5321 对 SMTP 事务的路径元素有一个限制:256但这包括电子邮件地址周围的尖括号,因此电子邮件地址的最大长度为 254 个字符。”

-EDIT-

According to RFC 2606 .localhost is reserved domain name and its length is 9 characters.
That is the longest I am aware of.

-END OF EDIT-

However, I think that you should care about email address length and not only TLD length.
Below is a quote from this article.
The email address length is 254 characters:

There appears to be some confusion over the maximum valid email address size. Most people believe it to be 320 characters (64 characters for the username + 255 characters for the domain + 1 character for the @ symbol). Other sources suggest 129 (64 + 1 + 64) or 384 (128+1+255, assuming the username doubles in length in the future).

This confusion means you should heed the 'robustness principle' ("developers should carefully write software that adheres closely to extant RFCs but accept and parse input from peers that might not be consistent with those RFCs." - Wikipedia) when writing software that deals with email addresses. Furthermore, some software may be crippled by naive assumptions, e.g. thinking that 50 characters is adequate (examples). Your 200 character email address may be technically valid but that will not help you if most websites or applications reject it.

The actual maximum email length is currently 254 characters:

"The original version of RFC 3696 did indeed say 320 was the maximum length, but John Klensin (ICANN) subsequently accepted this was wrong."

"This arises from the simple arithmetic of maximum length of a domain (255 characters) + maximum length of a mailbox (64 characters) + the @ symbol = 320 characters. Wrong. This canard is actually documented in the original version of RFC3696. It was corrected in the errata. There's actually a restriction from RFC5321 on the path element of an SMTP transaction of 256 characters. But this includes angled brackets around the email address, so the maximum length of an email address is 254 characters."

疧_╮線 2025-01-11 18:13:37

最长的拉丁字母是 .MUSEUM(来源),但也有一些带有特殊的人物。其中最长的是 XN--CLCHC0EA0B2G2A9GCD。此外,在短时间内,您可以以高价保留您自己的 TLD,因此时间可能会更长。

The longest with latin letters is .MUSEUM (source), but there are some with special characters. The longest from them is XN--CLCHC0EA0B2G2A9GCD. Also, in a short time, it will be possible to reserve your own TLD for a high price and so it will be possible to be longer.

杯别 2025-01-11 18:13:37

由于我是一名 .net 开发人员,以下是确定当前可用的最长 TLD 的 java 脚本表示形式。这将返回您可以在 RegEx 中使用的最长 TLD 的长度。

请尝试以下代码片段

function getTLD() {
    var length = 0;
    var longest;
    var request = new XMLHttpRequest();

    request.open('GET', 'http://data.iana.org/TLD/tlds-alpha-by-domain.txt', true);
    request.send(null);
    request.onreadystatechange = function () {
        if (request.readyState === 4 && request.status === 200) {
            var type = request.getResponseHeader('Content-Type');
            if (type.indexOf("text") !== 1) {
                var tldArr = request.responseText.split('\n'); 
                tldArr.splice(0, 1);

                for (var i = 0; i < tldArr.length; i++) {
                    if (tldArr[i].length > length) {
                        length = tldArr[i].length;
                        longest = tldArr[i];
                    }
                } 

                console.log("Longest >> " + longest + " >> " + length);
                return length;
            }
        }
    }
}
<button onclick="getTLD()">Get TLD</button>

Since I'm a .net developer following is the java-script representation of determining the longest TLD currently available.this will return the length of the longest TLD which you would be able to use in your RegEx.

please try the following Code Snippet

function getTLD() {
    var length = 0;
    var longest;
    var request = new XMLHttpRequest();

    request.open('GET', 'http://data.iana.org/TLD/tlds-alpha-by-domain.txt', true);
    request.send(null);
    request.onreadystatechange = function () {
        if (request.readyState === 4 && request.status === 200) {
            var type = request.getResponseHeader('Content-Type');
            if (type.indexOf("text") !== 1) {
                var tldArr = request.responseText.split('\n'); 
                tldArr.splice(0, 1);

                for (var i = 0; i < tldArr.length; i++) {
                    if (tldArr[i].length > length) {
                        length = tldArr[i].length;
                        longest = tldArr[i];
                    }
                } 

                console.log("Longest >> " + longest + " >> " + length);
                return length;
            }
        }
    }
}
<button onclick="getTLD()">Get TLD</button>

若有似无的小暗淡 2025-01-11 18:13:37

迄今为止最长的 TLD 是.xn--vermgensberatung-pwb,在 Punycode 中为 24 个字符,解码后为 17 个[vermögensberatung]。如果没有 Punycode,则为 .northwesternmutual.travelersinsurance,均为 18 个字符。

但是,域名(TLD 之前的内容)最长可达 63 个字符,如下所示: http: //www.thelongestdomainnameintheworldandthensomeandthensomemoreandmore.com

Longest TLD up to date is .xn--vermgensberatung-pwb, at 24 characters in Punycode and 17 when decoded [vermögensberatung]. With no Punycode it would be .northwesternmutual or .travelersinsurance both at 18 characters.

However, a domain name, the thing that goes before an TLD, can be up to 63 characters long, as seen here: http://www.thelongestdomainnameintheworldandthensomeandthensomemoreandmore.com

在巴黎塔顶看东京樱花 2025-01-11 18:13:37

这是 PHP 代码,用于获取最新的竖线分隔的 UTF-8 TLD 列表,以便直接在正则表达式中使用:

<?php 
  function getTLDs($separator){
    $tlds=file('http://data.iana.org/TLD/tlds-alpha-by-domain.txt');
    array_shift($tlds); // remove heading comment
    usort($tlds,function($a,$b){ return strlen($b)-strlen($a); }); // sort from longest to shortest
    return implode($separator,array_map(function($e){ return idn_to_utf8(trim(strtolower($e))); },$tlds));
  }
  echo getTLDs('|');
?>

要匹配您可以使用的主机名像这样:

$tlds=getTLDs('|');
if (preg_match("{([\da-z\.-]+)\.($tlds)}u",$address)) {
  ..
}

This is PHP code to get up-to-date vertical bar separated UTF-8 TLDs list to be used directly in a regular expression:

<?php 
  function getTLDs($separator){
    $tlds=file('http://data.iana.org/TLD/tlds-alpha-by-domain.txt');
    array_shift($tlds); // remove heading comment
    usort($tlds,function($a,$b){ return strlen($b)-strlen($a); }); // sort from longest to shortest
    return implode($separator,array_map(function($e){ return idn_to_utf8(trim(strtolower($e))); },$tlds));
  }
  echo getTLDs('|');
?>

To match a host name you could use it like this:

$tlds=getTLDs('|');
if (preg_match("{([\da-z\.-]+)\.($tlds)}u",$address)) {
  ..
}
病女 2025-01-11 18:13:37

TLD 可以是任意长度。新顶级域名 (TLD) 一直在发生。将来将会有更多的 TLD 不受目前监管大多数 TLD 的实体的监管。我们将来也不会像现在一样使用电子邮件。也就是说:

您永远不需要验证电子邮件地址。如果您想让人们慢下来并了解他们是否真的是人类,请添加验证码。如果您需要确认工作电子邮件,请发送一封包含他们可以打开的验证链接的电子邮件。如果您不限制提交可能生成诸如发送验证电子邮件之类的内容,那么您是否确认该地址在技术上有效并不重要,无论如何,它都会在那时被滥用。

A TLD can be any length at all. New TLDs happen all the time. In the future there will be more TLDs not regulated by the entity currently regulating the majority of TLDs. We also won't use email in the future as we presently do. That said:

You don't need to validate an email address ever. If you want to slow people down and have an idea as to whether they're actually human, include a CAPTCHA. If you need to confirm working email, send an email with a validation link they can open. If you aren't throttling submissions of things that can generate things like emails being sent for verification, it won't matter whether you're confirming the address is technically valid anyway, it will be abused at that point regardless.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文