using System.Text.RegularExpressions;
public static void Main()
var stringToTest="email@gmail.com";
var stringtoTest2= "NotAValid@h.com";
pattern = "^([0-9a-zA-Z]([-\\.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$";
if (Regex.IsMatch(stringToTest , pattern))
Console.WriteLine(stringToTest+ " is Valid Email address ");
Console.WriteLine(stringToTest + " is Not a Valid Email address");
if (Regex.IsMatch(stringtoTest2 , pattern))
Console.WriteLine(stringtoTest2+ " is Valid Email address ");
Console.WriteLine(stringtoTest2 + " is Not a Valid Email address");