public static boolean checkidcard(String idcard) { String idcardnum=idcard.trim(); int len=idcardnum.length(); //身份证权重 int weight[]= {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}; char validate[]= {'1','0','X','9','8','7','6','5','4','3','2','x'}; int sum=0; int mode=0; if(len==18||len==15) { if(len==18) { for(int i=0;i<len-1;i++) { sum=sum+(idcardnum.charAt(i)-'0')*weight[i]; } mode=sum%11; if(validate[mode]==idcardnum.charAt(17)) { return true; } else return false; } } else { return false; } return true; }