using System;
using System.Text.RegularExpressions;
public class RegexUtilities
{
public static void Main()
{
string[] emailAddresses = { "a.j@p.com", "d.j@s.p.com",
"j@m.p.com", "j.@s.p.com",
"j@p.com9" };
foreach (string emailAddress in emailAddresses)
{
if (RegexUtilities.IsValidEmail(emailAddress))
Console.WriteLine("Valid: {0}", emailAddress);
else
Console.WriteLine("Invalid: {0}", emailAddress);
}
}
public static bool IsValidEmail(string strIn)
{
return Regex.IsMatch(strIn, @"^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$");
}
}
|