发布网友 发布时间:2022-04-23 08:48
共3个回答
热心网友 时间:2023-10-08 22:41
private static final String onlyNum = "^[0-9]*{1}“;
/**
* 验证身份证号码
* @param id_number
* @return
*/
public static Boolean checkNID(String id_number){
Boolean isRight = false;
if(id_number.length() != 15 && id_number.length() != 18){
return false;
}
String string = id_number.substring(0, id_number.length() - 1);
if(!string.matches(onlyNum)){
return false;
}
if(id_number.length() == 15){
return is15IDNumberRight(id_number);
} else if(id_number.length() == 18){
return is18IDNumberRight(id_number);
}
return isRight;
}
热心网友 时间:2023-10-08 22:41
正则表达式:
判定代码如下:
if ((!Regex.IsMatch(txtID.Text, @"^(^\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$",RegexOptions.IgnoreCase)))
{
MessageBox.Show("请输入正确的身份证号码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
热心网友 时间:2023-10-08 22:42
正则表达式就可以了