香港身份证规则

 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值