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

Posted feiyucha

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用正则表达式验证密码长度相关的知识,希望对你有一定的参考价值。

实现效果:

  技术分享图片

知识运用:

  技术分享图片

实现代码:

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

 

以上是关于使用正则表达式验证密码长度的主要内容,如果未能解决你的问题,请参考以下文章