php 一个电子邮件地址中可以有多少个@ 符号?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12355858/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:24:40  来源:igfitidea点击:

How many @ symbol can be in an email address?

phpemail-validation

提问by droidlabour

Is there any rule for having a specified amount of @ symbol in any email id. Just come to my mind if we're to check if an email id is valid or not using PHP.

是否有任何规则可以在任何电子邮件 ID 中包含指定数量的 @ 符号。如果我们要检查电子邮件 ID 是否有效或未使用 PHP,请想一想。

回答by PeeHaa

If enquoted multiple @are allowed. I have to ask why do you need this information. Please please pleasedo not try to write a regex / function or whatever to validate emailaddresses. You have to worry about 3 rfc's (and perhaps 4 if you want to take into account unicode). And you willfail and it willdrive you mad.

如果引用多个@是允许的。我不得不问你为什么需要这些信息。请请不要尝试写入验证emailaddresses一个正则表达式/函数或什么的。您必须担心 3 个 rfc(如果您想考虑 unicode,则可能需要 4 个)。你失败,它会让你发疯。

See my previous answer for more information and a regex you may use if you have an older version of PHP

如果您有旧版本的 PHP,请参阅我之前的答案以获取更多信息和正则表达式

P.S.

聚苯乙烯

In case someone missed my point: do nottry to come up with some validation of your own to validate emailaddresses yourself "ever".

如果有人错过了我的观点:你尝试拿出一些自己的验证,以验证自己emailaddresses“永远”。

回答by Alnitak

There can be any number (within the size limits of an email address) except that the last one must be the separator between the domain name and the "local part".

可以有任何数字(在电子邮件地址的大小限制内),但最后一个必须是域名和“本地部分”之间的分隔符。

If an @or any other "unusual" characters (as defined by RFC 5322) exist in the local part it MUSTappear in quotes, e.g: "user@something"@example.com

如果本地部分中存在一个@或任何其他“不寻常”字符(如RFC 5322所定义),则它必须出现在引号中,例如:"user@something"@example.com

回答by Quentin

There is no specific limit on @characters.

@字符没有特定限制。

"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.comis a valid address.

"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com是一个有效的地址。

See also, the Wikipedia pageon the subject.

另请参阅有关该主题的维基百科页面

回答by shail

An addr-spec is a specific Internet identifier that contains a locally interpreted string followed by the at-sign character ("@", ASCII value 64) followed by an Internet domain. The locally interpreted string is either a quoted-string or a dot-atom. If the string can be represented as a dot-atom (that is, it contains no characters other than atext characters or "." surrounded by atext characters), then the dot-atom form SHOULD be used and the quoted- string form SHOULD NOT be used. Comments and folding white space SHOULD NOT be used around the "@" in the addr-spec.

addr-spec 是一个特定的 Internet 标识符,它包含一个本地解释的字符串,后跟 at-sign 字符(“@”,ASCII 值 64),后跟一个 Internet 域。本地解释的字符串是带引号的字符串或点原子。如果字符串可以表示为一个点原子(也就是说,它不包含除 atext 字符或被 atext 字符包围的“.”之外的任何字符),那么应该使用点原子形式,而不应该使用带引号的字符串形式使用。addr-spec 中的“@”周围不应使用注释和折叠空格。

See :- http://tools.ietf.org/html/rfc5322#section-3.4.1

请参阅:- http://tools.ietf.org/html/rfc5322#section-3.4.1

回答by Jared Paolin

My real question is would it make sense to have two @ symbols in an email?
How would it work?

我真正的问题是在电子邮件中包含两个 @ 符号有意义吗?
它会如何运作?

I would use filter_var()with FILTER_VALIDATE_EMAIL. Below is a sample use and outputs,

我会用filter_var()FILTER_VALIDATE_EMAIL。以下是示例使用和输出,

function testemail($email) {
    echo "'$email' => ";
    var_dump(filter_var($email, FILTER_VALIDATE_EMAIL));    
    echo "<br />";
}

testemail('');
testemail('myemailsample.com');
testemail('myemail@sample');
testemail('[email protected]');
testemail('myemail@@sample.com');
testemail('myemail@[email protected]');

Output,

输出,

'' => bool(false)
'myemailsample.com' => bool(false)
'myemail@sample' => bool(false)
'[email protected]' => string(18) "[email protected]"
'myemail@@sample.com' => bool(false)
'myemail@[email protected]' => bool(false)

'' => bool(false)
'myemailsample.com' => bool(false)
'myemail@sample' => bool(false)
'[email protected]' => string(18) "[email protected]"
'myemail@@sample.com' => bool(false)
'myemail@[email protected]' => bool(false)

回答by Jordi Kroon

To check for a valid email adress I should use the filter_var function. It will validate the string and return true or false. You don't have to think about regular expressions.

要检查有效的电子邮件地址,我应该使用 filter_var 函数。它将验证字符串并返回 true 或 false。您不必考虑正则表达式。