CSharp · Console
using System;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
var stringToTest="[email protected]";
var stringtoTest2= "[email protected]";
string pattern = null;
pattern = "^([0-9a-zA-Z]([-\\.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$";
//check first string
if (Regex.IsMatch(stringToTest , pattern))
{
Console.WriteLine(stringToTest+ " is Valid Email address ");
}
else
{
Console.WriteLine(stringToTest + " is Not a Valid Email address");
}
//check second string
if (Regex.IsMatch(stringtoTest2 , pattern))
{
Console.WriteLine(stringtoTest2+ " is Valid Email address ");
}
else
{
Console.WriteLine(stringtoTest2 + " is Not a Valid Email address");
}
}
}