C# regular expression to validate email

using System;
using System.Text.RegularExpressions;

namespace ConsoleApp375
{
    class Program
    {
        static void Main(string[] args)
        {
            RegularExpressionDemo();
            Console.ReadLine();
        }

        static void RegularExpressionDemo()
        {
            string emailPattern = @"^[\w!#$%&'*+\-/=?\^_`{|}~]+(\.[\w!#$%&'*+\-/=?\^_`{|}~]+)*@((([\-\w]+\.)+[a-zA-Z]{2,4})|(([0-9]{1,3}\.){3}[0-9]{1,3}))\z";
            Regex regex = new Regex(emailPattern);
            string myMail = "aaa@163.com";
            var match = regex.Match(myMail);
            Console.WriteLine(match.Success);
        }
    }
}

 

posted @ 2019-09-08 13:32  FredGrit  阅读(288)  评论(0编辑  收藏  举报