使用正则表达式验证身份证号

实现效果:

关键知识:

 

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            if (IsValidate(textBox1.Text.ToString()))
                MessageBox.Show("输入正确,验证通过","提示:");
            else
                MessageBox.Show("格式有误,请细心!","提示:");
        }
        //定义方法
        public bool IsValidate(string str_person) {
            return System.Text.RegularExpressions.
                Regex.IsMatch(str_person,@"(^\d{18}$)|(^\d{15}$)");
        }

猜你喜欢

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