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

· 13년 전 · 6399 · 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개

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

프로그램

+
제목 글쓴이 날짜 조회
13년 전 조회 2,986
13년 전 조회 2,304
13년 전 조회 4,056
13년 전 조회 4,085
13년 전 조회 3,051
13년 전 조회 4,488
13년 전 조회 8,155
13년 전 조회 3,717
13년 전 조회 2,325
13년 전 조회 3,457
13년 전 조회 3,420
13년 전 조회 4,179
13년 전 조회 2,180
13년 전 조회 3,275
13년 전 조회 2,113
13년 전 조회 3,340
13년 전 조회 4,252
13년 전 조회 2,561
13년 전 조회 5,470
13년 전 조회 1.2만
13년 전 조회 2,699
13년 전 조회 4,085
13년 전 조회 3,698
13년 전 조회 4,352
13년 전 조회 7,638
13년 전 조회 3,984
13년 전 조회 4,589
13년 전 조회 2,608
13년 전 조회 2,332
13년 전 조회 3,445
13년 전 조회 7,469
13년 전 조회 3,038
13년 전 조회 6,329
13년 전 조회 2,241
13년 전 조회 5,686
13년 전 조회 2,837
13년 전 조회 2,672
13년 전 조회 2,939
13년 전 조회 2,872
13년 전 조회 2,123
13년 전 조회 2,094
13년 전 조회 2.2만
13년 전 조회 2,055
13년 전 조회 2,652
13년 전 조회 2,631
13년 전 조회 2,888
13년 전 조회 5,063
13년 전 조회 2,277
13년 전 조회 3,768
13년 전 조회 6,400
13년 전 조회 2,237
13년 전 조회 5,429
13년 전 조회 2,605
13년 전 조회 5,370
13년 전 조회 2,473
13년 전 조회 3,356
13년 전 조회 2,459
13년 전 조회 3,717
13년 전 조회 9,520
13년 전 조회 3,522
13년 전 조회 3,306
13년 전 조회 3,147
13년 전 조회 2,147
13년 전 조회 3,656
13년 전 조회 3,457
13년 전 조회 2,205
13년 전 조회 2,746
13년 전 조회 2,187
13년 전 조회 2,278
13년 전 조회 2,770
13년 전 조회 5,134
13년 전 조회 3,653
13년 전 조회 3,871
13년 전 조회 5,239
13년 전 조회 5,001
13년 전 조회 4,680
13년 전 조회 5,570
13년 전 조회 2,524
13년 전 조회 7,491
13년 전 조회 2,875
13년 전 조회 2,724
13년 전 조회 4,911
13년 전 조회 4,610
13년 전 조회 6,721
13년 전 조회 4,264
13년 전 조회 4,934
13년 전 조회 2,611
13년 전 조회 2,413
13년 전 조회 3,607
13년 전 조회 2,380
13년 전 조회 3,754
13년 전 조회 3,066
13년 전 조회 2,698
13년 전 조회 3,656
13년 전 조회 3,586
13년 전 조회 2,865
13년 전 조회 2,380
13년 전 조회 2,932
13년 전 조회 2,413
13년 전 조회 2,765