MDN上的邮箱格式验证问题
图1
图2
图1验证失败没问题,怎么邮箱格式验证中图2就成功了呢,这明显也是错误的邮箱格式吧?这是MDN上的一个例子,是我哪里理解错了吗?
例子地址:邮箱验证格式
回答
为什么不可以?
邮箱格式为 用户名@域名
组成。
用户名不用说了,只说域名部分。
有关域名的组成,是由相关规范的,主要内容来自与 DNS 规范。
其中《RFC-1034》中的第 3 章第 5 小节写道:
Note that while upper and lower case letters are allowed in domain names, no significance is attached to the case. That is, two names with the same spelling but different case are to be treated as if identical.
The labels must follow the rules for ARPANET host names. They must start with a letter, end with a letter or digit, and have as interior characters only letters, digits, and hyphen. There are also some restrictions on the length. Labels must be 63 characters or less.
注意加粗部分文字,明确指出 “域名要遵循 ARPANET 的主机名格式:必须以字母开头、以字母或者数字结尾,中间部分为字母、数字或连字符(即 -
),长度必须是 63 个字符或者更短。
后面还有《RFC-1035》,内容就不放了,大体相同,只是额外增加了 .
这个字符,提出了 “标签”(label)这个概念,也就是每个小数点分隔的部分。
到此时,域名还不支持数字放到开头的表示方式。
不过在随后的《RFC-1101》中第 3 章第 1 小节中,又有了新的补充:
The current syntax for network names, as defined by [RFC 952] is an alphanumeric string of up to 24 characters, which begins with an alpha, and may include “.” and “-“ except as first and last characters. This is the format which was also used for host names before the DNS. Upward compatibility with existing names might be a goal of any new scheme.
However, the present syntax has been used to define a flat name space, and hence would prohibit the same distributed name allocation method used for host names. There is some sentiment for allowing the NIC to continue to allocate and regulate network names, much as it allocates numbers, but the majority opinion favors local control of network names. Although it would be possible to provide a flat space or a name space in which, for example, the last label of a domain name captured the old-style network name, any such approach would add complexity to the method and create different rules for network names and host names.
For these reasons, we assume that the syntax of network names will be the same as the expanded syntax for host names permitted in [HR]. The new syntax expands the set of names to allow leading digits, so long as the resulting representations do not conflict with IP addresses in decimal octet form. For example,3Com.COM
and3M.COM
are now legal, although26.0.0.73.COM
is not. See [HR] for details.
注意加粗部分,它表明:“新的语法标准允许以数字开头,但结果不能与十进制八位字节形式的 IP 地址冲突。”
在更后来的《RFC-2181》,又补充了内容,规定了 “除了限制长度(包括每个标签之间的长度以及完整域名总长)外,任何二进制字符串都可以作为标签”。到了这个时候,任意字符都可以用在域名中了。
最后总结一下现存的 DNS 域名有关之规定:
- 长度限制:每个标签长度在 63 个字符以内,域名全长(含小数点)不超过 255 个字符;
- 不区分大小写,常规默认小写;
- 特殊字符:需要用
三位八进制 ASCII 码
格式转义; - 中、日、韩等非拉丁文字符域名:需要进行 punycode 转码。
所以,纯数字域名是符合标准的。
可能你会理解为一级域名这种概念,最小的必须是 example.com
、example.cn
之类的二段式结构。
但其实 com
、cn
本身也是域名,是顶级域名。
域名的颁发、管理等工作是由 ICANN 组织进行的,这个组织不发布 1
这样的纯数字域名,不代表它不符合域名的规则。
以上是 MDN上的邮箱格式验证问题 的全部内容, 来源链接: utcz.com/a/27301.html