The solution for validating an email address (RFC compliant) in .net C#

It’s a common question : “How can I validate one email address” ?

There are 0b10 (2) types of developers : lazy and ignorant.

  1. Lazy people always wins, because they do not reinventing the wheel, they prefer to search already done API.
  2. Ignorant people will probably use Regexp (I love regexp but not in this case) or write a new algorithm, they could spend few hours or days to implement the full RFC, good luck !

So the code is obvisouly server side, and in .net :

try
{
   new HttpRequestMessage().Headers.From = "mail@foo.com";
   //here the mail is valid
}
catch(FormatException ex)
{
// here the email is invalid
}
This entry was posted in Non classé. Bookmark the permalink.

Comments are closed.