JavaScript

주민번호 검사 (3)
  • 조회수 4,991
  • 작성일 2011-09-08
  •  

function ssn_check(fld) {
    var sum_1 = 0;
    var sum_2 = 0;
    var at=0;
    var juminno= fld;
    sum_1 = (juminno.charAt(0)*2)+
            (juminno.charAt(1)*3)+
            (juminno.charAt(2)*4)+
            (juminno.charAt(3)*5)+
            (juminno.charAt(4)*6)+
            (juminno.charAt(5)*7)+
            (juminno.charAt(6)*8)+
            (juminno.charAt(7)*9)+
            (juminno.charAt(8)*2)+
            (juminno.charAt(9)*3)+
            (juminno.charAt(10)*4)+
            (juminno.charAt(11)*5);
    sum_2=sum_1 % 11;

    if (sum_2 == 0)
        at = 10;
    else
    {
        if (sum_2 == 1)
            at = 11;
        else
            at = sum_2;
    }
    att = 11 - at;

    if (juminno.charAt(12) != att ||
        juminno.substr(2,2) < '01' ||
        juminno.substr(2,2) > '12' ||
        juminno.substr(4,2) < '01' ||
        juminno.substr(4,2) > '31' ||
        juminno.charAt(6) > 4)
    {
       return false;
    }
    else {
       return true;
    }
}

function fwrite_check() {

  var f = document.fwrite;
  var ssnpattern = /(^[0-9]{13}$)/;
  var ssn = f.ssn1.value + f.ssn2.value;
  var hak = ssnpattern.test(ssn);
 if (!hak) {
  alert("주민등록번호를 13자리 숫자로 입력하십시오.");
  f.ssn1.focus();
  return false;
 }
  var ssn_checked = ssn_check(ssn);
 if (!ssn_checked) {
  alert("올바른 주민등록번호가 아닙니다.");
  f.ssn1.focus();
  return false;
 }

  f.action = 'sub04_proc.php';
  f.submit();
}