身份证正则表达式
检测身份证是否合法
import java.util.*;
public class ifLegal{
String sex;
String birthday;
static Boolean islegal;
public static Boolean judgeLegal(String IDnum) {
String regex = "[1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(10|11|12))([0-2][1-9]|30|31)\\d{3}[0-9Xx]";
if(IDnum.length()!=18) {
islegal=false;
return false;
}
if(!IDnum.matches(regex)) {
return false;
}
return true;
}
public static void main(String []args) {
System.out.println("请输入身份证号");
Scanner reader = new Scanner(System.in);
String number = reader.nextLine();
Boolean judgeresult = judgeLegal(number);
if(judgeresult) {
System.out.println("输入合法");
}
else
{
System.out.println("输入有误");
}
}
}
特别注意:
仅供参考学习,转载请附上原文链接
分享学习心得,如有侵权,望联系本人处理
还在读大学的程序员,项目经验少,如有纰漏,感谢指正
需要源代码请联系本人
谢谢配合
如果这篇文章对您有帮助,小小的点个赞,算是给小学弟的鼓励吧!谢谢大佬!!/呱呱.jpg