首页 > 其他 > 详细

香港身份证规则

时间:2019-09-18 09:43:35      阅读:99      评论:0      收藏:0      [点我收藏+]
 1  public static void main(String[] args) {
 2         String str = "C668668(9)";
 3         test te = new test();
 4         boolean aa = te.isHKIdentiy(str);
 5 
 6         System.out.println(aa);
 7 
 8     }
 9 
10     public boolean isHKIdentiy(String identity) {
11         if (identity == null){
12             return false;
13         }
14         if (identity.length() == 10) {
15 
16             String id1 = null;
17             String id6 = null;
18             String id8 = null;
19             String id9 = null;
20             String id10 = null;
21             id6 = identity.substring(1, 7);
22             id1 = identity.substring(0, 1);
23             id8 = identity.substring(7, 8);
24             id9 = identity.substring(8,9);
25             id10 = identity.substring(9, 10);
26             int aa0 = Integer.valueOf(id6);
27             int aa1 = Integer.valueOf(id1.charAt(0));
28             int aa2 = Integer.valueOf(identity.substring(1, 2));
29             int aa3 = Integer.valueOf(identity.substring(2, 3));
30             int aa4 = Integer.valueOf(identity.substring(3, 4));
31             int aa5 = Integer.valueOf(identity.substring(4, 5));
32             int aa6 = Integer.valueOf(identity.substring(5, 6));
33             int aa7 = Integer.valueOf(identity.substring(6, 7));
34             int aa9 = Integer.valueOf(id9.charAt(0));
35             if ((id8.equals("(")&& id10.equals(")") && (100000 <= aa0 && aa0 <= 999999) && (64 < aa1 && aa1 < 91) && (65 == aa9 || (48 <= aa9 && aa9 <= 57)))) {
36                 Integer sum = (aa1-64)* 8 + aa2 * 7 + aa3 * 6 + aa4 * 5 + aa5 * 4 + aa6 * 3 + aa7 * 2;
37                 Integer ys = Math.floorMod(sum, 11);
38                 String bb = String.valueOf(11 - ys);
39                 if ((ys == 1 && (id9.equals("A")) || (ys == 0 && (id9.equals("1"))) || ((1 < ys && ys < 11) && (id9.equals(bb))))) {
40                     return true;
41 
42                 } else return false;
43 
44             } else
45                 return false;
46         } else
47             return false;
48     }

 

技术分享图片

 

香港身份证规则

原文:https://www.cnblogs.com/bai123/p/11539663.html

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!