주민번호 타당성 검사

Seon Kim·2024년 1월 31일

<body>
<form id='myform' method='post' action='member_join.jsp'>
  <table border=0  align='center'>
    <tr>
      <td>주민번호</td>
      <td>
          <input type='text' id='jumin1' size=6 maxlength=6 onkeyup='move()'> -
          <input type='text' id='jumin2' size=7 maxlength=7>
		  <input type='button' value="검사" onclick='checkInput()'>	
		  <input type='reset' value="취소">
      </td>
    </tr>
   </table>
</form>

<script>
	
	var myform = document.getElementById("myform");
	var jumin1 = document.getElementById("jumin1");
	var jumin2 = document.getElementById("jumin2");
	
function move(){
	 if(jumin1.value.length == 6){
		jumin2.focus();
	 }
}

function checkInput() {
	if(jumin1.value=='') {
        alert("주민등록번호를 앞자리를 입력하세요!");
        jumin1.focus();
        return;
    }
    if(jumin1.value.length != 6) {
        alert("주민등록번호의 앞자릿수가 맞지 않습니다.");
        jumin1.value = '';
        jumin1.focus();
        return;
    }
    if(jumin2.value=='') {
        alert("주민등록번호를 뒷자리를 입력하세요!");
        jumin2.focus();
        return;
    }
    if(jumin2.value.length != 7) {
        alert("주민등록번호의 뒷자릿수가 맞지 않습니다.");
        jumin2.focus();
        jumin2.value = '';
        return;
    }
    if(!juminCheck(jumin1.value + jumin2.value)) {
        alert("주민등록번호가 잘못되었습니다.");
        jumin1.focus();
        return;
    }	
	alert("올바른 주민번호 입니다.");	
}

function juminCheck(jumin) { 
	// jumin = "9501011234567";
    var total = 0;
    var total2;
//    total += parseInt(jumin.substr(0,1)) * 2;
//    total += parseInt(jumin.substr(1,1)) * 3;
//    total += parseInt(jumin.substr(2,1)) * 4;
//    total += parseInt(jumin.substr(3,1)) * 5;
//    total += parseInt(jumin.substr(4,1)) * 6;
//    total += parseInt(jumin.substr(5,1)) * 7;
//    total += parseInt(jumin.substr(6,1)) * 8;
//    total += parseInt(jumin.substr(7,1)) * 9;
//    total += parseInt(jumin.substr(8,1)) * 2;
//    total += parseInt(jumin.substr(9,1)) * 3;
//    total += parseInt(jumin.substr(10,1)) * 4;
//    total += parseInt(jumin.substr(11,1)) * 5;
    
    mul = [ 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5 ];

	for (var i = 0; i <= 11; i++) {
		total += parseInt(jumin.substr(i, 1)) * mul[i];
	}    

    total %= 11;			// total = total % 11;
    total2 = 11 - total;
    if(total2 > 9)
        total2 = total2 % 10;

    if(total2 != parseInt(jumin.substr(12,1))) {	// 체크용 번호와 비교
        return false;
    }else{
        return true;
	}
}
</script>
profile
개발 어린이

0개의 댓글