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

IsValidEmailAddress

Check wheter a string is an valid e-mail address

Source

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

Example

bool f = "test@test.com".IsValidEmailAddress();

Author: Scott Guthrie

Submitted on: 21 aug. 2007

Language: C#

Type: System.String

Views: 12579