주민번호, 외국인번호 검사 스크립트

· 13년 전 · 5029 · 2
// 내국인
function ssnCheck(ssn) {
  var lastid, li_mod, li_minus, li_last;
  var checkValue = 0;

  if (ssn.length != 13) return false;
  lastid = parseFloat(ssn.substring(12,13));   
  
  checkValue += (parseInt(ssn.substring(0,1)) * 2) + (parseInt(ssn.substring(1,2)) * 3) 
+ (parseInt(ssn.substring(2,3)) * 4) + (parseInt(ssn.substring(3,4)) * 5) 
+ (parseInt(ssn.substring(4,5)) * 6) + (parseInt(ssn.substring(5,6)) * 7) 
+ (parseInt(ssn.substring(6,7)) * 8) + (parseInt(ssn.substring(7,8)) * 9) 
+ (+parseInt(ssn.substring(8,9)) * 2)  + (parseInt(ssn.substring(9,10)) * 3) 
+ (parseInt(ssn.substring(10,11)) * 4) + (parseInt(ssn.substring(11,12)) * 5);

  li_mod = checkValue % 11;
  li_minus = 11 - li_mod;
  li_last = li_minus % 10;

  if (li_last != lastid) return false;
  
  return true;
}


// 외국인
function isFrgNo(fgnno) { 
  var sum = 0; 
  var odd = 0; 
  buf = new Array(13); 

  for(i=0; i<13; i++) buf[i] = parseInt(fgnno.charAt(i)); 

  odd = buf[7]*10 + buf[8]; 

  if(odd%2 != 0) return false; 

  if((buf[11]!=6) && (buf[11]!=7) && (buf[11]!=8) && (buf[11]!=9)) return false; 

  multipliers = [2,3,4,5,6,7,8,9,2,3,4,5]; 

  for(i=0, sum=0; i<12; i++) sum += (buf[i] *= multipliers[i]); 

  sum = 11 - (sum%11); 

  if(sum >= 10) sum -= 10; 

  sum += 2; 
  if(sum >= 10) sum -= 10; 

  if(sum != buf[12]) return false;

  return true; 
}

<script>
function number_check(){ 
var f = document.frm;
var ssn1 = f.jumin1.value;
var ssn2 = f.jumin2.value;
var ssn = ssn1 + ssn2;

if(ssn2.substring(0,1) == '1' || ssn2.substring(0,1) == '3' || 
ssn2.substring(0,1) == '2' || ssn2.substring(0,1) == '4') {
// 국내 주민번호 체크
if (ssnCheck(ssn) == false ) {
alert('주민번호를 정확히 입력하십시오.');
f.jumin1.value = '';
f.jumin2.value = '';
f.jumin1.focus();
return;
}
} else {
// 외국인 등록번호 체크
if(isFrgNo(ssn) == false) {
alert( "외국인 등록번호를 정확히 입력하십시오." );
f.jumin1.value = '';
f.jumin2.value = '';
f.jumin1.focus();
return;
}   
}
}
</script>

<form name="frm" onsubmit="return false;">
<input type="text" name="jumin1"> - <input type="password" name="jumin2"> <button onclick="number_check()">체크</button>
</form>
|

댓글 2개

필요할때 헤매는 소스 감사합니다.
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
12년 전 조회 1,568
12년 전 조회 889
12년 전 조회 2,756
12년 전 조회 2,618
12년 전 조회 1,645
12년 전 조회 3,058
12년 전 조회 6,675
12년 전 조회 2,278
12년 전 조회 870
12년 전 조회 2,040
12년 전 조회 1,995
12년 전 조회 2,743
12년 전 조회 735
12년 전 조회 1,826
12년 전 조회 915
12년 전 조회 1,902
12년 전 조회 2,813
12년 전 조회 1,375
12년 전 조회 4,006
12년 전 조회 1만
12년 전 조회 1,251
12년 전 조회 2,576
12년 전 조회 2,255
12년 전 조회 3,116
12년 전 조회 6,151
12년 전 조회 2,774
12년 전 조회 3,098
12년 전 조회 1,107
12년 전 조회 895
12년 전 조회 1,981
12년 전 조회 6,002
12년 전 조회 1,608
12년 전 조회 4,835
12년 전 조회 1,077
12년 전 조회 4,231
12년 전 조회 1,379
12년 전 조회 1,221
12년 전 조회 1,814
12년 전 조회 1,436
12년 전 조회 712
12년 전 조회 682
12년 전 조회 2.1만
12년 전 조회 646
12년 전 조회 1,201
12년 전 조회 1,207
12년 전 조회 1,445
13년 전 조회 3,597
13년 전 조회 832
13년 전 조회 2,339
13년 전 조회 5,030
13년 전 조회 791
13년 전 조회 3,975
13년 전 조회 1,166
13년 전 조회 3,897
13년 전 조회 1,036
13년 전 조회 1,886
13년 전 조회 1,055
13년 전 조회 2,282
13년 전 조회 8,068
13년 전 조회 2,060
13년 전 조회 1,850
13년 전 조회 1,665
13년 전 조회 722
13년 전 조회 2,236
13년 전 조회 1,975
13년 전 조회 755
13년 전 조회 1,328
13년 전 조회 750
13년 전 조회 1,038
13년 전 조회 1,322
13년 전 조회 3,706
13년 전 조회 2,235
13년 전 조회 2,432
13년 전 조회 3,792
13년 전 조회 3,599
13년 전 조회 3,269
13년 전 조회 4,138
13년 전 조회 1,156
13년 전 조회 6,100
13년 전 조회 1,503
13년 전 조회 1,336
13년 전 조회 3,528
13년 전 조회 3,155
13년 전 조회 5,303
13년 전 조회 2,828
13년 전 조회 3,466
13년 전 조회 1,151
13년 전 조회 967
13년 전 조회 2,155
13년 전 조회 927
13년 전 조회 2,340
13년 전 조회 1,644
13년 전 조회 1,243
13년 전 조회 2,234
13년 전 조회 2,438
13년 전 조회 1,446
13년 전 조회 931
13년 전 조회 1,462
13년 전 조회 958
13년 전 조회 1,339
🐛 버그신고