<html>
<head>
<title>문서의 제목</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script language="javascript">
function clicktest() {
var jumin = document.frm.jumin1.value + document.frm.jumin2.value;
if(jumin.length != 13) {
window.alert("입력길이가 틀립니다.");
return;
}
for(var i=0; i < jumin.length ; i++) {
if(isNaN(parseInt(jumin.charAt(i)))){
window.alert("문자열로 입력할 수 없습니다.");
return;
}
}
var checkbit = new Array(2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5);
var total = 0;
for(var i=0; i<checkbit.length ; i++) {
total += parseInt(jumin.charAt(i)) * checkbit[i];
}
var calbit = (11 - (total % 11)) % 10;
var lastbit = jumin.charAt(12);
output = "계산된 마지막 자리 : " + calbit + "\n";
output += "주민등록번호 마지막 자리 : " + lastbit + "\n";
document.frm.output.value = output;
}
</script>
</head>
<body>
<form name="frm">
주민등록번호를 입력하세요 :<br><br>
<input type="text" name="jumin1" size="30" maxlength="6">
~
<input type="text" name="jumin2" size="30" maxlength="7">
<input type="button" value="검사하기" onclick="clicktest()">
<br><br>
<textarea name="output" cols="60" rows="10"></textarea>
</form>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script language="javascript">
function clicktest(){
// var jumin1 = document.forms[0].jumin1.value;
var jumin1 = document.frm.jumin1.value;
var jumin2 = document.frm.jumin2.value;
var lenjumin1 = document.frm.jumin1.value.length;
var jumin= jumin1+jumin2;
var total=0;
for(var j=0; j<jumin.length; j++){
if(j<=7)
total += parseInt(jumin.charAt(j)) * (j+2);
else if(j>=8 && j<=11)
total += parseInt(jumin.charAt(j)) * (j-6);
}
var check= (11-(total%11))%10
if(parseInt(check) == parseInt(jumin.charAt(12))){
var output=jumin1 +"-" +jumin2;
document.frm.output.value="올바른 주민번호입니다\n" +output +"\n";
}else document.frm.output.value="올바른 주민번호가 아닙니다"+check +" "+total;
if(lenjumin1 !=6 || jumin2.length != 7)
document.frm.output.value="주민등록번호 틀림!!";
for(var i=0; i<jumin.length; i++) {
if(isNaN(parseInt(jumin.charAt(i))))
document.frm.output.value=("문자로 입력할 수 없습니다.");
}
}
</script>
</head>
<body>
<form name="frm">
주민등록번호를 입력하세요<br>
<input type="text" name="jumin1" size="6" maxlength="6">
-
<input type="text" name="jumin2" size="7" maxlength="7">
<input type="button" value="검사하기" onclick="clicktest()">
<br>
<textarea name="output" cols="20" rows="5"></textarea>
</form>
</body>
</html>
'Study > Programming' 카테고리의 다른 글
자바 equals (0) | 2009.05.15 |
---|---|
자바스크립트 문자열 비교 (0) | 2009.05.14 |
자바스크립트 Java Script (0) | 2009.05.13 |
CSS (0) | 2009.05.12 |
HTML2 (0) | 2009.05.11 |