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.
There is no specific limit on @
characters.
"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com
is a valid address.
See also, the Wikipedia page on the subject.
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,
function testemail($email) {
echo "'$email' => ";
var_dump(filter_var($email, FILTER_VALIDATE_EMAIL));
echo "<br />";
}
testemail('');
testemail('myemailsample.com');
testemail('myemail@sample');
testemail('myemail@sample.com');
testemail('myemail@@sample.com');
testemail('myemail@sa@mple.com');
Output,
'' => bool(false)
'myemailsample.com' => bool(false)
'myemail@sample' => bool(false)
'myemail@sample.com' => string(18) "myemail@sample.com"
'myemail@@sample.com' => bool(false)
'myemail@sa@mple.com' => bool(false)
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.
See :- http://tools.ietf.org/html/rfc5322#section-3.4.1
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.
If enquoted multiple @
are allowed. I have to ask why do you need this information. Please please please do 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 will fail and it will drive you mad.
See my previous answer for more information and a regex you may use if you have an older version of PHP
P.S.
In case someone missed my point: do not try to come up with some validation of your own to validate emailaddresses yourself "ever".
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 MUST appear in quotes, e.g: "user@something"@example.com