VS2005中邮箱正则表达式

今天需要一个关邮电子邮箱输入的正则表达式,于是在控制台程序做了一个测试
static void Main(string[] args)
        {
            string emailPattern = @"^([a-z0-9A-Z]+[-|\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\.)+[a-zA-Z]{2,}$";
            Console.Write("Enter an e-mail address:");
            string emailInput = Console.ReadLine();
            bool match = Regex.IsMatch(emailInput, emailPattern);
            if (match)
            {
                Console.WriteLine("E-mail address is valid");
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("Suppliied input is not a valid e-mail address");
                Console.ReadLine();
            }

RegEx类是.NET框架中一个处理正则表达式的关键类。RegEx类包含了一个名为IsMatch的静态方法,它返回一个布尔值,这个布尔值说明指定的输入串是否与一个给定的正则表达式匹配。

RegEx类是在System.Text.RegularExpressions命名空间
原文地址:https://www.cnblogs.com/Bigkangaroo/p/1119496.html