当前位置 : 主页 > 编程语言 > c语言 >

C# regular expression to validate email

来源:互联网 收集:自由互联 发布时间:2021-06-25
using System; using System.Text.RegularExpressions; namespace ConsoleApp375{ class Program { static void Main( string [] args) { RegularExpressionDemo(); Console.ReadLine(); } static void RegularExpressionDemo() { string emailPattern = @" ^
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 = "[email protected]";
            var match = regex.Match(myMail);
            Console.WriteLine(match.Success);
        }
    }
}
网友评论