使用正则表达式验证汉字输入

实现效果:

  

知识运用:

  

实现代码: 

        private void button1_Click(object sender, EventArgs e)
        {
            if (!textBox1.Text.Equals(string.Empty))
            {
                if (System.Text.RegularExpressions.Regex.IsMatch(textBox1.Text, "[\u4e00-\u9fa5]{1,}"))
                    MessageBox.Show("任务完成,赏啤酒一箱", "恭喜!");
                else
                    MessageBox.Show("看来你需要的是再来一次哟!!", "细心点"); textBox1.Text = "";
            }
        }

猜你喜欢

转载自www.cnblogs.com/feiyucha/p/10051117.html
今日推荐