[精讚] [會員登入]
330

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

你可能感興趣的文章

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

Spring Boot Maven wrappers maven, mvnw, build command

java.time 時間 instant java.time

[vue.js] 設定 content type 今天在wickt 端怎麼就是收不到vue.js 以post 傳過來的資料 找了好久才發現 application/jso

java lambda files filter java, files filter, lambda

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

我有話要說

>>

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

訪客留言

[無留言]

隨機好文

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

download a file from spring boot controllers ownload a file from spring boot controllers

java.time 時間 instant java.time

2018 hoc 掃地機器人 掃地機器人只能打掃沒有障礙物(桌椅、牆壁)的範圍,請寫程式控制機器人打掃餐廳的所有走道, 並在清掃完畢後回到充電器。

臺中市雲端校務系統與Windows AD帳號整合(2) 安裝Active Directory網域服務