一个为同一国家内的人书写的电话号码,在其他任何地方都是有歧义的。同样的数字,有无前导零或国家呼叫代码,代表的是不同的号码。E.164 通过固定唯一的书写形式消除了这种歧义。
国际号码的结构,分为八个独立类别。
ITU-T E.164 建议书来自国际电信联盟(管理编号方案的联合国机构),它为每一类国际号码规定了数字结构和路由分析方法:
Recommendation ITU-T E.164 provides the number structure and functionality for the eight categories of numbers used for international public telecommunication:
这些类别涵盖的远不只是国家号码。地理区域是八类之一,其余还包括全球业务、其他全球业务、全球卫星业务、网络、国家群组、试验资源,以及物联网与机器对机器通信的业务和应用。它还为号码本身提供了正式名称:
Annex A provides additional information on the structure and function of international public telecommunication numbers (hereafter referred to as "international E.164 numbers").
国家呼叫代码,然后是国内号码,没有其他任何内容。
+31612345678 是一个荷兰手机号码。31 是国家呼叫代码,612345678 是国内号码。缺少什么和包含什么同样重要:没有空格、没有连字符、没有括号、没有国内拨号习惯中的前导零,也没有国际接入前缀(如 011 或 00)。
前导的 + 是标记符号而非数字。它告诉读取该字符串的系统后面是一个国际号码。没有人会拨打它。因此请存储数字部分,将标点符号视为展示层的内容。
长到你不应该去检查。
可读的原始资料对此的表述比通常引用的规则更窄。Google 的 libphonenumber FAQ 将 15 位数字的上限仅限于国内号码部分,并指出并非所有国家都遵守:
We support parsing and storing numbers from a minimum length of two digits to a maximum length of 17 digits currently (excluding country calling code). The ITU standard says the national significant number should not be longer than fifteen digits, but empirically this has been proven not to be followed by all countries.
因此,一个拒绝超过 15 位数字的校验器会拒绝真实存在的号码。
实用的规则是解析而非测量长度。通过号码库或查询可以判断一个号码是否在可分配范围内,而长度比较做不到这一点。电话号码验证检查了什么介绍了每种检查所确认的内容。