C# Email Validation

The System.Net.Mail Had the mail address class which can be used to validate Email Ids

public static bool IsValidEmail(string emailaddress)
{
try
{
MailAddress m = new MailAddress(emailaddress);
return true;
}
catch (FormatException)
{
return false;
}
}

The code above can be used to validate Email Ids . If the Email Id is in the wrong format , It throws the Format Exception which in turn can be used as an approach to handle the invalid Email Ids . However The use of regular Expressions is the best approach as It is highly Flexible.

Hope You Liked Reading .Happy Coding 🙂 .

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s