17 בפבר׳ 2022, 14:41

מי שרוצה זה קוד שבודק את התעודת זהות האם תקין
ב php

<?php
  $id = $_GET["id"];
  
  $the_id = str_split($id);
  for ($i=9; count($the_id) < $i;) { 
    array_unshift($the_id,0);
  }
  $plus = 1;
  $all = 0;
  for ($i=0; $i < 9; $i++) { 
    $sum = $the_id[$i] * $plus;
    if($sum > 9){
      $a = str_split($sum);
      $al = $a[0] + $a[1];
      $sum = $al;
    }
    $all += $sum;
    if ($plus == 1) {
      $plus = 2;
    } else {
      $plus = 1;
    }
  }
  $o = $all % 10;
  if ($o == 0) {
    $ok = "its ok";
  }else{
    $ok = "wooops";
  }
  echo $ok;


?>

ב javascript

<!DOCTYPE html>
<html lang="he">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  <script type="text/javascript">
    function LegalTz() {
      var id = document.getElementById("input").value;
      var id_ = Array.from(String(id), Number);
      for (let index = 9; id_.length < index;) {
        id_.unshift(0);
      }
      var myBol = true;
      var sum = 0;
      var zzz;
      for (let i = 0; i < id_.length; i++) {
        if (myBol == true) {
          zzz = id_[i] * 1;
          myBol = false;
        } else {
          zzz = id_[i] * 2;
          myBol = true;
        }
        if (zzz > 9) {
          var ss = Array.from(String(zzz.toString()), Number);
          zzz = ss[0] + ss[1];
        }
        sum = sum + zzz;
      }
      if (sum % 10 > 0) {
        $(".dd").css("background-color", "red");
      } else {
        $(".dd").css("background-color", "green");
      }
    }
  </script>
  <style>
    .dd {
      height: 40px;
      width: 60px;
    }
  </style>
</head>

<body>
  <input id="input" type="number" />
  <button onclick="LegalTz()">בדוק</button>
  <div class="dd"></div>
</body>

</html>