Awesome trick to validate Email Address in C# .Net (without Regular Expression)


 

Holla,

Recently I came across this fine, precise, code by Rion Williams, to check and validate an Email Address.
The code uses System.Net.Mail Namespace to check email address and returns True/False.

Very Effective and Easy!

Source Link

bool IsValidEmail(string email)
{
    try {
        var addr = new System.Net.Mail.MailAddress(email);
        return true;
    }
    catch {
        return false;
    }
}

Please feel free to share your thoughts, Or similar code you’ve encountered recently in Comment section.

Advertisements

4 thoughts on “Awesome trick to validate Email Address in C# .Net (without Regular Expression)

  1. Hi, this namespace allows the email address without dot (.) operator in it.
    ex- emailaddress – aaa@gmailcom

    its telling the address is valid and sends value as true.

    This does not show correct validation

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 )

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s