[精讚] [會員登入]
340

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

你可能感興趣的文章

刪除資料夾內的檔案 lambda 一行文 Arrays.stream(new File("/folder/path").

讀取特定資料夾下的xls檔 讀取特定資料夾下的xls檔

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

Spring Boot Maven wrappers maven, mvnw, build command

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

java-身份証字號驗証 FormatCheck.java public class FormatCheck { private volatile

我有話要說

>>

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

訪客留言

[無留言]

隨機好文

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

vue.js modal 作兩個選項按鈕並導向不同頁面 vue.js modal 作兩個選項按鈕

利用maven建立一個可執行的jar檔 利用maven建立一個可執行的jar檔

java.time 時間 instant java.time

ArrayList 想移除特定值 想移出water, 使用lambda 的方式如下 List<String> fruits = new Arr