Hire Me

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

Find out how to validate an e-mail address using C# and the MailObject Class


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

;

Have your say

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


Did you find this tutorial useful or informative?

Why not give me a call on 07990 523015 or contact me for a no-obligation chat about how I can help you with any software issues you're having - I have availability as of December 2017 and am available for both remote working and in-house projects subject to your location.