E-Mail Address Verification in C# using Regular Expressions

Kundnani.Rt
Posted by Kundnani.Rt under C# category on | Points: 40 | Views : 1290
Foll. code verifies E-Mail Address format.

static void Main(string[] args)
{
string patternForEMail = @"\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b";

Regex rgx = new Regex(patternForEMail, RegexOptions.IgnoreCase);

Console.Write("Enter the E-Mail Address: ");

MatchCollection matches = rgx.Matches(Console.ReadLine());

if (matches.Count > 0)
{
Console.WriteLine("Valid E-Mail...");
}
else
{
Console.WriteLine("In-Valid E-Mail...");
}

Console.Read();
}

Comments or Responses

Login to post response