메뉴 건너뛰기

Dev tips

http://blog.naver.com/joker2501?Redirect=Log&logNo=40113161108http://www.virhac.com/bbs/?bid=javascript&page=5&pid=96function chkBizRegNo(bizID) // 사업자등록번호 체크
{
        var checkID = new Array(1, 3, 7, 1, 3, 7, 1, 3, 5, 1);
        var i, Sum=0, c2, reminder;

        bizID = bizID.replace(/-/gi,'');

        for (i=0; i<=7; i++){
                Sum += checkID[i] * bizID.charAt(i);
        }

        c2 = "0" + (checkID[8] * bizID.charAt(8));
        c2 = c2.substring(c2.length - 2, c2.length);

        Sum += Math.floor(c2.charAt(0)) + Math.floor(c2.charAt(1));

        reminder = (10 - (Sum % 10)) % 10 ;

        if(bizID.length != 10) {
                return false;
        } else if (Math.floor(bizID.charAt(9)) != reminder) {
                return false;
        } else {
                return true;
        }
}

function fnRRNCheck(rrn) // 유효성검사. 사용법fnRRNCheck("8201011234567");
{
    if (fnrrnCheck(rrn) || fnfgnCheck(rrn)) {
        return true;
    }
    return false;
}

function fnrrnCheck(rrn) // 주민등록번호유효성검사.
{
    var sum = 0;
    if (rrn.length != 13) {
        return false;
    }
    else if (rrn.substr(6, 1) != 1 && rrn.substr(6, 1) != 2 && rrn.substr(6, 1) != 3 && rrn.substr(6, 1) != 4) {
        return false;
    }
    for (var i = 0; i < 12; i++) {
        sum += Number(rrn.substr(i, 1)) * ((i % 8) + 2);
    }
    if (((11 - (sum % 11)) % 10) == Number(rrn.substr(12, 1))) {
        return true;
    }
    return false;
}

function fnfgnCheck(rrn) // 외국인등록번호유효성검사.
{
    var sum = 0;
    if (rrn.length != 13) {
        return false;
    }
    else if (rrn.substr(6, 1) != 5 && rrn.substr(6, 1) != 6 && rrn.substr(6, 1) != 7 && rrn.substr(6, 1) != 8) {
        return false;
    }
    if (Number(rrn.substr(7, 2)) % 2 != 0) {
        return false;
    }
    for (var i = 0; i < 12; i++) {
        sum += Number(rrn.substr(i, 1)) * ((i % 8) + 2);
    }
    if ((((11 - (sum % 11)) % 10 + 2) % 10) == Number(rrn.substr(12, 1))) {
        return true;
    }
    return false;
}