Wednesday, February 17, 2010

Regular expression for Email in .net

const string expression = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
@"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
@".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";

Regex regex = new Regex(expression);

if (!regex.IsMatch(inputEmail))
{
return "Not a Valid Email";
}

No comments: