이전생략...
<input type="text" name="jumin1<%=i%>" value="" style="width:93; " maxlength="6"/> -
<input type="password" name="jumin2<%=i%>" value="" style="width:93; " maxlength="7"/>
이후생략...
<script type="text/javascript">
var strtxt_residentno1= eval("form1.jumin1.value"); //첫 번째 필드
var strtxt_residentno2= eval("form1.jumin2.value"); //두번째 필드
if(strtxt_residentno1.length != 0)
{
var chk=0;
var yy=eval("form1.jumin1.value").substring(0, 2); //출생년도 추출
var mm=eval("form1.jumin1.value").substring(2, 4); //출생월 추출
var dd=eval("form1.jumin1.value").substring(4, 6); //출생일 추출
var sex=eval("form1.jumin2.value").substring(0, 1); //성별 추출
//첫 번째필드가 6자리가 아니거나 출생월일이 날짜 형식에 위배될때
if((strtxt_residentno1.length!=6) || (mm<1 || mm>12 || dd<1 || dd>31)){
//form1.jumin1.value='';
alert('본인 주민번호 첫번째자리 형식이 잘못 되었습니다.');
//form1.jumin1.focus();
return;
}
//성별형식이 틀리거나 두 번째 필드가 7자리가 아닐때
if((strtxt_residentno2.length!=7) || (sex!=1 && sex!=2 )){
alert('본인 주민번호 두번째자리 형식이 잘못 되었습니다.');
return;
}
//주민등록번호 체크에 관한
for(i=0; i<=5; i++)
chk=chk+((i%8+2)*parseInt(strtxt_residentno1.substring(i, i+1)));
for(i=6; i<=11; i++)
chk=chk+((i%8+2)*parseInt(strtxt_residentno2.substring(i-6, i-5)));
chk=(11-(chk%11))%10;
if(chk!=strtxt_residentno2.substring(6, 7)){
alert('주민번호 형식이 잘못 되었습니다.');
return;
}
}
</script>
주민번호 체크.. 역시 유용해..
'Computerscience > JavaScript' 카테고리의 다른 글
영문 또는 공백만 입력 가능한 스크립트 (0) | 2009.02.13 |
---|