电子邮件地址中允许使用哪些字符? [英] What characters are allowed in an email address?

查看:20
本文介绍了电子邮件地址中允许使用哪些字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是在询问完整的电子邮件验证.

I'm not asking about full email validation.

我只想知道电子​​邮件地址的 user-nameserver 部分允许使用哪些字符.这可能过于简单化了,也许电子邮件地址可以采用其他形式,但我不在乎.我只询问这个简单的形式:user-name@server(例如wild.wezyr@best-server-ever.com)和两部分允许的字符.

I just want to know what are allowed characters in user-name and server parts of email address. This may be oversimplified, maybe email adresses can take other forms, but I don't care. I'm asking about only this simple form: user-name@server (e.g. wild.wezyr@best-server-ever.com) and allowed characters in both parts.

推荐答案

参见 RFC 5322: Internet Message格式,在较小程度上,RFC 5321:简单邮件传输协议.

See RFC 5322: Internet Message Format and, to a lesser extent, RFC 5321: Simple Mail Transfer Protocol.

RFC 822 也涵盖电子邮件地址,但主要涉及其结构:

RFC 822 also covers email addresses, but it deals mostly with its structure:

 addr-spec   =  local-part "@" domain        ; global address     
 local-part  =  word *("." word)             ; uninterpreted
                                             ; case-preserved
 
 domain      =  sub-domain *("." sub-domain)     
 sub-domain  =  domain-ref / domain-literal     
 domain-ref  =  atom                         ; symbolic reference

和往常一样,维基百科有一篇不错的关于电子邮件地址的文章:

And as usual, Wikipedia has a decent article on email addresses:

电子邮件地址的本地部分可以使用以下任何 ASCII 字符:

The local-part of the email address may use any of these ASCII characters:

  • 大写和小写拉丁字母 AZaz;
  • 数字09
  • 特殊字符!#$%&'*+-/=?^_`{|}~;
  • dot .,前提是它不是第一个或最后一个字符,除非被引用,并且除非被引用,否则它不会连续出现(例如 John..Doe@example.com 是不允许的,但 John..Doe"@example.com 是允许的);
  • space 和 "(),:;<>@[] 字符是允许有限制的(它们只允许在带引号的字符串中,如下文所述,并且此外,反斜杠或双引号前面必须有反斜杠);
  • 允许注释在本地部分的任一端带有括号;例如john.smith(comment)@example.com(comment)john.smith@example.com 都等价于 john.smith@example.com.
  • uppercase and lowercase Latin letters A to Z and a to z;
  • digits 0 to 9;
  • special characters !#$%&'*+-/=?^_`{|}~;
  • dot ., provided that it is not the first or last character unless quoted, and provided also that it does not appear consecutively unless quoted (e.g. John..Doe@example.com is not allowed but "John..Doe"@example.com is allowed);
  • space and "(),:;<>@[] characters are allowed with restrictions (they are only allowed inside a quoted string, as described in the paragraph below, and in addition, a backslash or double-quote must be preceded by a backslash);
  • comments are allowed with parentheses at either end of the local-part; e.g. john.smith(comment)@example.com and (comment)john.smith@example.com are both equivalent to john.smith@example.com.

除 ASCII 字符外,截至 2012 年您可以使用国际以上字符 U+007F,编码为UTF-8如RFC 6532 规范中所述,并在维基百科.请注意,截至 2019 年,这些标准仍标记为 Proposed,但正在缓慢推出.此规范中的更改基本上将国际字符添加为有效的字母数字字符(atext),而不会影响允许的 & 规则.限制特殊字符,如 !#@:.

In addition to ASCII characters, as of 2012 you can use international characters above U+007F, encoded as UTF-8 as described in the RFC 6532 spec and explained on Wikipedia. Note that as of 2019, these standards are still marked as Proposed, but are being rolled out slowly. The changes in this spec essentially added international characters as valid alphanumeric characters (atext) without affecting the rules on allowed & restricted special characters like !# and @:.

有关验证,请参阅使用正则表达式验证电子邮件地址.

domain 部分的定义如下:

协议的 Internet 标准(征求意见)要求组件主机名标签只能包含 ASCII 字母 az(以不区分大小写的方式),数字 09,以及连字符 (-).RFC 952 中主机名的原始规范要求标签不能以数字开头或以连字符开头,并且不得以连字符结尾.但是,随后的规范(RFC 1123)允许主机名标签以数字开头.不允许使用其他符号、标点符号或空格.

The Internet standards (Request for Comments) for protocols mandate that component hostname labels may contain only the ASCII letters a through z (in a case-insensitive manner), the digits 0 through 9, and the hyphen (-). The original specification of hostnames in RFC 952, mandated that labels could not start with a digit or with a hyphen, and must not end with a hyphen. However, a subsequent specification (RFC 1123) permitted hostname labels to start with digits. No other symbols, punctuation characters, or blank spaces are permitted.

这篇关于电子邮件地址中允许使用哪些字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆