[精讚] [會員登入]
796

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

你可能感興趣的文章

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

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

java lambda files filter java, files filter, lambda

Spring Boot Maven wrappers maven, mvnw, build command

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

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

隨機好文

vue.js components 多個組件的呈現 vue.js 組件 component

臺中市雲端校務系統與Windows AD帳號整合(4) 雲端校務系統與Windows AD的架構

ubuntu ufw ufw 簡易筆記 原則禁止,例外開放 ufw default deny 啟動ufw sudo ufw enable 關掉

在docker裡跑spring boot+mongo(二) 使用docker-compose 管理多個container 前篇使用docker run 一次建一個container

google sheet 限制使用者以點選的方式填答 google sheet 限制使用者以點選的方式填答