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

· 13년 전 · 5889 · 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,485
13년 전 조회 1,807
13년 전 조회 3,543
13년 전 조회 3,553
13년 전 조회 2,520
13년 전 조회 3,954
13년 전 조회 7,631
13년 전 조회 3,199
13년 전 조회 1,774
13년 전 조회 2,934
13년 전 조회 2,884
13년 전 조회 3,636
13년 전 조회 1,620
13년 전 조회 2,701
13년 전 조회 1,633
13년 전 조회 2,816
13년 전 조회 3,700
13년 전 조회 2,107
13년 전 조회 4,900
13년 전 조회 1.1만
13년 전 조회 2,178
13년 전 조회 3,559
13년 전 조회 3,160
13년 전 조회 3,912
13년 전 조회 7,084
13년 전 조회 3,578
13년 전 조회 4,047
13년 전 조회 2,028
13년 전 조회 1,795
13년 전 조회 2,891
13년 전 조회 6,908
13년 전 조회 2,498
13년 전 조회 5,740
13년 전 조회 1,777
13년 전 조회 5,128
13년 전 조회 2,299
13년 전 조회 2,123
13년 전 조회 2,510
13년 전 조회 2,324
13년 전 조회 1,566
13년 전 조회 1,541
13년 전 조회 2.1만
13년 전 조회 1,516
13년 전 조회 2,080
13년 전 조회 2,118
13년 전 조회 2,341
13년 전 조회 4,495
13년 전 조회 1,709
13년 전 조회 3,233
13년 전 조회 5,890
13년 전 조회 1,677
13년 전 조회 4,867
13년 전 조회 2,069
13년 전 조회 4,790
13년 전 조회 1,910
13년 전 조회 2,785
13년 전 조회 1,933
13년 전 조회 3,170
13년 전 조회 8,985
13년 전 조회 2,956
13년 전 조회 2,766
13년 전 조회 2,549
13년 전 조회 1,591
13년 전 조회 3,126
13년 전 조회 2,910
13년 전 조회 1,652
13년 전 조회 2,219
13년 전 조회 1,607
13년 전 조회 1,862
13년 전 조회 2,250
13년 전 조회 4,600
13년 전 조회 3,129
13년 전 조회 3,319
13년 전 조회 4,693
13년 전 조회 4,457
13년 전 조회 4,112
13년 전 조회 4,982
13년 전 조회 2,020
13년 전 조회 6,971
13년 전 조회 2,334
13년 전 조회 2,173
13년 전 조회 4,391
13년 전 조회 4,052
13년 전 조회 6,197
13년 전 조회 3,758
13년 전 조회 4,418
13년 전 조회 2,101
13년 전 조회 1,873
13년 전 조회 3,116
13년 전 조회 1,859
13년 전 조회 3,241
13년 전 조회 2,543
13년 전 조회 2,137
13년 전 조회 3,144
13년 전 조회 3,116
13년 전 조회 2,374
13년 전 조회 1,856
13년 전 조회 2,409
13년 전 조회 1,897
13년 전 조회 2,278