我不是在询问完整的电子邮件验证。
我只想知道电子邮件地址的用户名
和服务器
部分允许使用哪些字符。这可能过于简单化,也许电子邮件地址可以采用其他形式,但我不在乎。我只询问这个简单的形式:user-name@server
(例如 wild.wezyr@best-server-ever.com)以及两个部分中允许的字符。
最佳答案
参见RFC 5322: Internet Message Format并且,在较小程度上,RFC 5321: Simple Mail Transfer Protocol .
RFC 822还涵盖电子邮件地址,但主要涉及其结构:
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
像往常一样,维基百科有一个不错的 article on email addresses :
The local-part of the email address may use any of these ASCII characters:
- uppercase and lowercase Latin letters
A
toZ
anda
toz
;- digits
0
to9
;- 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 tojohn.smith@example.com
.
除了 ASCII 字符外,as of 2012您可以使用国际 characters above U+007F
,编码为 UTF-8,如 RFC 6532 spec 中所述。并在 Wikipedia 上进行了解释。请注意,截至 2019 年,这些标准仍标记为“提议”,但正在缓慢推出。此规范中的更改本质上添加了国际字符作为有效的字母数字字符(atext),而不影响允许和限制的特殊字符(例如 !#
)的规则。和@:
.
有关验证,请参阅Using a regular expression to validate an email address .
domain
部分定义as follows :
The Internet standards (Request for Comments) for protocols mandate that component hostname labels may contain only the ASCII letters
a
throughz
(in a case-insensitive manner), the digits0
through9
, 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.
关于forms - 电子邮件地址中允许使用哪些字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2049502/