외국인 등록 번호 체크 루틴. 새로운 것

JS는 네이버 소스, PHP는 JS를 PHP로 바꾼 것.

# JS

// 외국인 등록번호 (20120703)

 function isForeSSN(socno)
 {
  var total =0;
  var parity = 0;
  var fgnNo = new Array(13);
  for(i=0;i < 13;i++) fgnNo[i] = parseInt(socno.charAt(i));

 // if(fgnNo[11] < 6) return false; //<---- 이부분 때문에 에러가나는 경우가 있을 것이다.(과거에는 체크해야하지만, 지금은 체크하면 안된다.

  if((parity = fgnNo[7]*10 + fgnNo[8])&1) return false;
  var weight = 2;
  for(i=0,total=0;i < 12;i++)
  {
   var sum = fgnNo[i] * weight;
   total += sum;
   if(++weight > 9) weight=2;
  }
  if((total = 11 - (total%11)) >= 10) total -= 10;
  if((total += 2) >= 10) total -= 10;
  if(total != fgnNo[12]) return false;
  return true;
 }

 

#PHP

 // 외국인 등록번호
  function  isForeSSN ($socno)
  {
   $total =0;
   $parity = 0;
   $fgnNo = array();
  for($i=0;$i < 13;$i++) $fgnNo[] = (int)$socno[$i];

  // if($fgnNo[11] < 6) return false;//<---- 이부분 때문에 에러가나는 경우가 있을 것이다.(과거에는 체크해야하지만, 지금은 체크하면 안된다.

   if(($parity = $fgnNo[7]*10 + $fgnNo[8])&1) return false;
   $weight = 2;
   for($i=0,$total=0;$i < 12;$i++)
   {
    $sum = $fgnNo[$i] * $weight;
    $total += $sum;
    if(++$weight > 9) $weight=2;
   }
   if(($total = 11 - ($total%11)) >= 10) $total -= 10;
   if(($total += 2) >= 10) $total -= 10;
   if($total != $fgnNo[12]) return false;
   return true;
  }

댓글
  • No Nickname
    No Comment
  • 권한이 없습니다.
    {{m_row.m_nick}}
    -
목록형 📷 갤러리형
제목
[기본형] HTML (with 부트스트랩5.3 , jquery 3.7, vue.js)
유용한 리눅스(LINUX) 명령어
[공지] 기술 게시판
3.31
4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.8
4.10
4.11
4.12
4.13
4.14
4.15
4.16
4.18
4.19
4.20
4.21
4.22
4.23
4.24
4.25
4.26
4.27
4.28
4.29
4.30
5.1
5.2
5.3
5.4