0

Possible Duplicate:
What characters are allowed in email address?

In C#, I don't know why MailAddress accept email address with single-quote, e.g. 'a''a'@gmail.com ... I also tested it in Hotmail and Gmail websites and they'll allow me to send an email to this wrong email addresses, but of course, later will get an failure email... even though during sign up, it doesn't allow new email with single quote '... Did you know a valid email address that have single-quote? is it valid format?

sorry, I means single-quote

Community
  • 1
  • 1
Jaider
  • 14,268
  • 5
  • 75
  • 82
  • 1
    Do you mean semicolon (`;`) or apostrophe (`'`)? – Mike Christensen Jul 09 '12 at 20:56
  • You have asked why semicolon (`;`) is allowed in e-mail address but your examples don't have that character. This question is off-topic for the forum, unless you can rephrase it as a coding error. Both semi-colon and apostrophe are valid in e-mail addresses. See http://en.wikipedia.org/wiki/Email_address – Miserable Variable Jul 09 '12 at 21:00
  • @MiserableVariable I didn't know these characters are valid in email addresses... most Regex email patterns aren't correct. I was thinking to use Regex validation before to create a MailAddress, but there is not need for it in sever side. (maybe we need a flexible email validation in the client side). Thanks for everything, The Wikipedia reference is really good. – Jaider Jul 11 '12 at 14:10
  • Validating e-mail addresses is extremely difficult. SO converted my answer to comment, I will try to undelete and add more original text; please accept it if you feel I answered your question. – Miserable Variable Jul 11 '12 at 22:08

2 Answers2

1

I would suggest you why don't you validate you email before you Send the email

This way you will get immediate feedback what is a valid email

Not the most ideal way to do it but you use the MailAddress class like this

MailAddress mailAddress = null;

    try
    {
       mailAddress = new MailAddress("a'@gmail.com");//email address with single quote in it
    }
    catch(Exception exception)
    {
      //If emailAdress is not correct then warn user
    }
HatSoft
  • 11,077
  • 3
  • 28
  • 43
0

As per RFC 2822, section 3.2.4, single quotes are allowed in email addresses (see how atext is defined):

atext           =       ALPHA / DIGIT / ; Any character except controls,
                        "!" / "#" /     ;  SP, and specials.
                        "$" / "%" /     ;  Used for atoms
                        "&" / "'" /
                        "*" / "+" /
                        "-" / "/" /
                        "=" / "?" /
                        "^" / "_" /
                        "`" / "{" /
                        "|" / "}" /
                        "~"

You may also want to quickly check your dubious email addresses against our free email validation service, that strictly follows the aforementioned RFC (among others) and is based on our email validation component for Microsoft .NET.

Efran Cobisi
  • 6,138
  • 22
  • 22