title: PESEL checksum validation(Javascript/HTML)
body: <p>Im a student currently studying from home and im seriously stuck on a Checksum problem. The script is supposed to validate the PESEL(Polish equivilant of a social security number i think), Anyway the checksum works as follows for
  PESEL: 70051012347</p>
  
  <p>PESEL:7,0,0,5,1,0,1,2,3,4 (7)</p>
  
  <pre><code>  (Multiply each Pesel number by its corresponding check number)
  </code></pre>
  
  <p>CHECK:1,3,7,9,1,3,7,9,1,3</p>
  
  <pre><code> (Sum Each number)
  </code></pre>
  
  <p>SUM: + 7,0,0,45,1,0,7,18,3,12 =93</p>
  
  <p>MOD: 93 MOD 10 = 3</p>
  
  <p>10 - 3 = 7(last digit of pesel)</p>
  
  <p>Where the MOD 10 doesn't equal 0, the result of sum%10 is subtracted from 10 and then matched with the final digit in the original number, if they match its good, if not its bad. All i need to have is a good or bad result.</p>
  
  <p>I'm pretty sure I have all of this fine in my code and there's a simple solution i just cant see it. Any help at all would be massively appreciated.</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;Pesel Checker&lt;/title&gt;
  &lt;script type="text/javascript"&gt;
  
  function peselgood(y)
  {
      //sample PESEL's
      //type 1
      //70051012347
      //02070803628
      //07020803628
      //type 2
      //83102570819
      if (y.length == 11) 
      {
  
          var arr = [1,3,7,9,1,3,7,9,1,3];
          var sum = 0;
  
          //hold original number 
          var a = parseInt(y);
  
          //First 10 digits without check number and convert to array
          y = y.substring(0,9);
          y = parseInt(y);
          var arr1 = new Array(10);
          arr1 = y;
  
          //muliply pesel digits by checksum digits
          for (var i = 0; i &lt; 10; i++)
          {
            sum += arr[i] * arr1[i];
          }
  
          sum = sum%10;
          if (sum !== 0)
          {
              sum = 10-sum;
              if(sum != a[10])
              {
                  return false;
              }
              else
              {
                  return true;
              }
          }
      }
      else
      {
          return false;
      }
  }
  
  
  function checkpesel()
  {
      num = document.getElementById("peselfield").value
      if (peselgood(num))
      {
          document.getElementById("peselfield").style.background="#00ff00";
      }
      else
      {
          document.getElementById("peselfield").style.background="#ff6666";
      }
  }
  
  &lt;/script&gt;
  
  
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div&gt;
      Check Sum Template
      &lt;br/&gt;&lt;br/&gt;
      &lt;form name="form"&gt;
          PESEL: 
          &lt;input type="text" id="peselfield" value="70051012347" /&gt; &lt;button type="button" onclick="checkpesel()"&gt;Check&lt;/button&gt;
          &lt;br/&gt;&lt;br/&gt;
      &lt;/form&gt; 
      &lt;/div&gt;
      &lt;br/&gt;&lt;br/&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>