[精讚] [會員登入]
353

java-身份証字號驗証

FormatCheck.java public class FormatCheck { private volatile

分享此文連結 //n.sfs.tw/10049

分享連結 java-身份証字號驗証@igogo
(文章歡迎轉載,務必尊重版權註明連結來源)
2016-10-18 23:58:27 最後編修
2016-10-18 23:58:27 By igogo
 

 

FormatCheck.java

public class FormatCheck {

    private volatile static FormatCheck uniqueInstance;

    private FormatCheck() {
    }

    public static FormatCheck getInstance() {
        if (uniqueInstance == null) {
            uniqueInstance = new FormatCheck();
        }
        return uniqueInstance;
    }

//https://www.javaworld.com.tw/jute/post/view?bid=35&id=33999&sty=3
    public boolean checkID(String Chk2) {
        String v[][] = {{"A", "台北市"}, {"B", "台中市"}, {"C", "基隆市"},
        {"D", "台南市"}, {"E", "高雄市"}, {"F", "台北縣"}, {"G", "宜蘭縣"},
        {"H", "桃園縣"}, {"J", "新竹縣"}, {"K", "苗栗縣"}, {"L", "台中縣"},
        {"M", "南投縣"}, {"N", "彰化縣"}, {"P", "雲林縣"}, {"Q", "嘉義縣"},
        {"R", "台南縣"}, {"S", "高雄縣"}, {"T", "屏東縣"}, {"U", "花蓮縣"},
        {"V", "台東縣"}, {"X", "澎湖縣"}, {"Y", "陽明山"}, {"W", "金門縣"},
        {"Z", "連江縣"}, {"I", "嘉義市"}, {"O", "新竹市"}
        };

        int inte = -1;
        String s1 = String.valueOf(Character.toUpperCase(Chk2.charAt(0)));
        for (int i = 0; i < 26; i++) {
            if (s1.compareTo(v[i][0]) == 0) {
                inte = i;
            }
        }
        int total = 0;
        int all[] = new int[11];
        String E = String.valueOf(inte + 10);
        int E1 = Integer.parseInt(String.valueOf(E.charAt(0)));
        int E2 = Integer.parseInt(String.valueOf(E.charAt(1)));
        all[0] = E1;
        all[1] = E2;
        try {
            for (int j = 2; j <= 10; j++) {
                all[j] = Integer.parseInt(String.valueOf(Chk2.charAt(j - 1)));
            }
            for (int k = 1; k <= 9; k++) {
                total += all[k] * (10 - k);
            }
            total += all[0] + all[10];
            if (total % 10 == 0) {
                return true;
            }
        } catch (Exception ee) {;
        }
        return false;
    }

}

 

Main.java

  public static void main(String[] args) {
        FormatCheck formatCheck = FormatCheck.getInstance();
        System.out.println(formatCheck.checkID("A123456789"));
    }

 

END

你可能感興趣的文章

keycloak 透過java client lib新增user 使用keycloak-admin-client lib maven <dependency> <gro

ArrayList 與 HashMap 範例 public static void main(String[] args) { String titleIds = &

Thread java thread

停止多執行緒 利用主程式呼叫多執行緒時, 要怎麼停止正在執行的多執行緒

java.time 時間 instant java.time

spring boot 使用jdbc連接mariadb spring boot, mariadb, jdbc, rowmapper

我有話要說

>>

限制:留言最高字數1000字。 限制:未登入訪客,每則留言間隔需超過10分鐘,每日最多5則留言。

訪客留言

[無留言]

隨機好文

[vue.js] 動態的props 做parent-child components 雙向綁定 vue.js props components camel-case

Arrays.asList 後想再add出現 UnsupportedOperationException 這個問題真是搞死我了 List<String> fruits = Arrays.asList("a

[scratch] 將角色物件放到清單中,並依序讀出每個角色的X值 將角色物件放到清單中,並依序讀出每個角色的X值

scratch 不重覆隨機取陣列值 隨機取數是在設計遊戲時, 很常用到的技巧 最簡單的就是使用運算積木裡的隨機取數範圍 但是, 如果我是想全部取出且不重覆,

網站無障礙規範 https://accessibility.ncc.gov.tw/News/Detail/3238?Category=4