C#后台验证身份证号码的一个方法

简单的调用了正则表达式进行简单的验证,记下来留着以后备用

1 if ((!Regex.IsMatch(txtID.Text, @"^(^d{15}$|^d{18}$|^d{17}(d|X|x))$",RegexOptions.IgnoreCase)))
2 {
3        MessageBox.Show("请输入正确的身份证号码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
4        return;
5 
6  }
View Code
原文地址:https://www.cnblogs.com/xujingyang/p/5560660.html