forms - 电子邮件地址中允许使用哪些字符?

标签 forms email email-validation email-address

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

我只想知道电子​​邮件地址的用户名服务器部分允许使用哪些字符。这可能过于简单化,也许电子邮件地址可以采用其他形式,但我不在乎。我只询问这个简单的形式: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 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 字符外,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 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.

关于forms - 电子邮件地址中允许使用哪些字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2049502/

相关文章:

c# - 如何远程验证电子邮件或检查电子邮件是否存在

html - 在 Firefox + Chrome 中禁用/删除默认输入类型 = "email"验证文本覆盖?

forms - HTML 点击提交按钮两次

python - 使用 WTForms 字段列表

php - HTML 输入数组

C# 在不知道扩展名的情况下向邮件消息添加附件

php - 为电子邮件激活链接 PHP 生成唯一字符串

ajax - 在fancyBox AJAX 表单提交后单击返回

Python - 通过 Outlook 2007/2010 和 win32com 发送 HTML 格式的电子邮件

java - java 验证电子邮件格式