使用正则表达式验证密码长度

实现效果:

  

知识运用:

  

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            if (Validate(textBox1.Text.ToString()))
                MessageBox.Show("验证通过");
            else
                MessageBox.Show("输入不符合");
        }
        //定义方法
        public bool Validate(string str) {
            return System.Text.RegularExpressions.
                Regex.IsMatch(str,@"^\d{16,18}$");
        }

猜你喜欢

转载自www.cnblogs.com/feiyucha/p/10018090.html