PL VATID validator


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function is_valid_nip($nip_number)
  2. {
  3. $nip_digits = array_filter(preg_split('//', $nip_number, -1, PREG_SPLIT_NO_EMPTY), 'is_numeric');
  4. $nip_length = count($nip_digits);
  5. $nip_sum = 0;
  6.  
  7. if(10 != $nip_length)
  8. { return false; }
  9.  
  10. foreach(array(6, 5, 7, 2, 3, 4, 5, 6, 7) as $weight)
  11. { $nip_sum += $weight * array_shift($nip_digits); }
  12.  
  13. return (($nip_sum % 11) == array_shift($nip_digits));
  14. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.