码迷,mamicode.com
首页 > Windows程序 > 详细

C# regular expression to validate email

时间:2019-09-08 14:25:39      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:ogr   nbsp   string   app   expr   style   col   pac   namespace   

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);
        }
    }
}

 

C# regular expression to validate email

标签:ogr   nbsp   string   app   expr   style   col   pac   namespace   

原文地址:https://www.cnblogs.com/Fred1987/p/11485676.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!