How to validate an e-mail address using C# and the MailObject Class

Posted on Sunday, December 14, 2014 at 12:48 AM into csharp, video, tutorial & code by Steve Woods.
Roughly a 1 minute read.

This is a dead simple way to validate a string of text to ensure that it is an e-mail address. The MailAddress object within the System.Net.Mail; namespace is RFC5322 compliant so if we try to create an instance of the object with an invalid e-mail address, it will throw an error that we can trap using a simple try { } catch {} block as follows.

Live Coding Example

Source Code



Please consider what you post!
Chillax if you're angry.