ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

Validate Email

Validate email id

Source

public static class Extensions
{
    public static bool        IsValidEmailAddress(this string s)
    {
        Regex regex = new          Regex(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$");
        return regex.IsMatch(s);
    }
}

Example

string customerEmailAddress = "test@test.com";
customerEmailAddress.IsValidEmailAddress()

Author: john

Submitted on: 29 jan. 2010

Language: C#

Type: system.mail

Views: 8137