Reputation: 8178
I'm not trying to come up with full email validation. I'm trying to prevent a specific problem:
I've had users use the contact form on my website, which asks for "Name
", "Email
" and "Message
", and just by hilarious mistake, I get the info, "First Name
", "Last Name
", "Message
", and I think to myself, 'Shit where did I leave my Yellow Pages?'
So, I don't want to validate email, I just want to remind people that it's not last name we're asking for it's email.
I'm thinking I check for an @
symbol, and I want to make sure I'm not neglecting valid emails.
Are there valid emails with no @
symbols in them?
Upvotes: 12
Views: 11004
Reputation: 20861
Yes, per RFC5322, every email address must have one at-sign, given the basic format of [email protected]
...
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.
But make sure not to validate for only one at-sign, because it's possible for an e-mail address to have several. After all, there are other RFCs!
RFC2822 gave us the ability to use quoted-strings in e-mail addresses...
3.2.2. Quoted characters
Some characters are reserved for special interpretation, such as delimiting lexical tokens. To permit use of these characters as uninterpreted data, a quoting mechanism is provided.
quoted-pair = ("" text) / obs-qp
So "@"@gmail.com
is a valid email address.
Don't forget about RFC5321, either! This defines another basic procedure for having as many @
signs as you want in your email address...
Note that the backslash, "\", is a quote character, which is used to indicate that the next character is to be used literally (instead of its normal interpretation). For example, "Joe\,Smith" indicates a single nine-character user name string with the comma being the fourth character of that string.
So, then, \@@gmail.com
is also a technically-valid email address.
Upvotes: 1
Reputation: 2111
Today, yes (see other answers); but the historic answer is: no.
The original standard (RFC822 ff) made it possible to have extremely short, valid and working email addresses like "i.me". (DDJ once ran a contest.) An @ was just indicating the postbox within a host; so if you owned the entire host (like, your own server or PC), then you didn't need an @.
The rules for checking email addresses were and are complicated. In an effort to simplify them somewhat, and match the bad practice of many broken "checkers", the - originally invalid - assumption an email address would contain an @ was eventually incorporated into the official standard.
Upvotes: 0
Reputation: 881303
As per RFC5322:
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.
So, yes, all email addresses must have the @
character.
Prior to the internet taking over the world, it was possible for email addresses to have other formats, like the FidoNet mail address 1:170/918.10
, user number 10 at FidoNet node 1:170/918
.
But given the ratio of internet users to FidoNet users currently stands at about a gazillion or more to one, that's for historical interest only.
Upvotes: 15
Reputation: 909
As defined in RFC5322, section 3.4.1:
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.
https://www.rfc-editor.org/rfc/rfc5322
Upvotes: 4
Reputation: 520
All valid email addresses contain the @ symbol. You can read the Internet Message Format standard for more information: https://www.rfc-editor.org/rfc/rfc5322
Specifically 3.4.1. Addr-spec specification: https://www.rfc-editor.org/rfc/rfc2822#section-3.4.1
Upvotes: 1