1. 程式人生 > >使用正則表示式驗證密碼長度

使用正則表示式驗證密碼長度

實現效果:

  

知識運用:

  

實現程式碼:

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