Posted By

tomaszsobczak on 01/16/10


Tagged

validator vatid


Versions (?)

PL VATID validator


 / Published in: PHP
 

  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  

You need to login to post a comment.