欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C# regular expression to validate email

程序员文章站 2022-10-13 15:34:37
using System; using System.Text.RegularExpressions; namespace ConsoleApp375 { class Program { static void Main(string[] args) { RegularExpressionDemo(... ......
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);
        }
    }
}