匹配汉字的正则表达式

class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string str = Console.ReadLine();
                string mode = "^[0-9a-zA-Z\u4E00-\u9FA5]+$";
                System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(mode);
                if (regex.IsMatch(str))
                {
                    Console.WriteLine("可以匹配输入!");
                }
                else
                {
                    Console.WriteLine("只能输入0-9、a-z、A-Z及汉字");
                }
            }
            //Console.Read();
        }
    }

posted @ 2012-02-16 09:15  liancs  阅读(259)  评论(0编辑  收藏  举报