private static boolean checkPersonId(String personId){ if(personId.length()!=18){ System.out.println("身份证号必须是18位数字"); return false; } if(personId.startsWith("0")){ System.out.println("身份证号不能是0开头"); return false; } for (int i = 0; i < personId.length()-1; i++) { char c=personId.charAt(i); if(!(c>='0'&&c<='9')){ return false; } } char endChar=personId.charAt(personId.length()-1); if((endChar>='0'&&endChar<='9')||(endChar=='x')||(endChar=='X')){ return true; }else{ return false; } }