Popular Posts
android.intent.action.SCREEN_ON & android.intent.action.SCREEN_OFF First, I've tried create a receiver to receive screen on/off and register receiver on AndroidManifest.xml like below, but unfortunately ... Multiple line of text limit With Sharepoint Designer, edit the page of list view. Add xsl template as below to override original template. Source template could be foun... Memo: Debounce Task To prevent multi-execution from caller in short time, use debounce for single execution. var debounce = function (func, threshold, execAsap...
Blog Archive
Stats
Validate social id
var JSUtil = {
    checkSocialID : function(IDStr){
        // 依照字母的編號排列,存入陣列備用。
        var letters = ['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'];
        // 儲存各個乘數
        var multiply = [1, 9, 8, 7, 6, 5, 4, 3, 2, 1];
        var nums = new Array(2);
        var firstChar;
        var firstNum;
        var lastNum;
        var total = 0;
        // 撰寫「正規表達式」。第一個字為英文字母,第二個字為1或2,後面跟著8個數字,不分大小寫。
        var regExpID=/^[a-z](1|2)\d{8}$/i;
        // 使用「正規表達式」檢驗格式
        if (IDStr.search(regExpID)==-1) {
            // 基本格式錯誤
            return false;
        } else {
            // 取出第一個字元和最後一個數字。
            firstChar = IDStr.charAt(0).toUpperCase();
            lastNum = IDStr.charAt(9);
        }
        // 找出第一個字母對應的數字,並轉換成兩位數數字。
        for (var i=0; i<26; i++) {
            if (firstChar == letters[i]) {
                firstNum = i + 10;
                nums[0] = Math.floor(firstNum / 10);
                nums[1] = firstNum - (nums[0] * 10);
                break;
            }
        }
        // 執行加總計算
        for(var i=0; i<multiply.length; i++){
            if (i<2) {
                total += nums[i] * multiply[i];
            } else {
                total += parseInt(IDStr.charAt(i-1)) * multiply[i];
            }
        }
        //規則一餘數為零,且檢查碼需為零
        if (lastNum == 0 && (total % 10) != lastNum ){
            return false;
        }
        //規則二餘數與檢查碼需相符
        if (lastNum != 0 && (10 - (total % 10))!= lastNum) {
            return false;
        }
        return true;
    }
}