Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Poprawny numer NIP, REGON lun PESEL, Funkcja, PHP4 i 5
ghostrider
post 11.11.2005, 12:45:20
Post #1





Grupa: Zarejestrowani
Postów: 135
Pomógł: 0
Dołączył: 30.09.2005
Skąd: k-rk

Ostrzeżenie: (0%)
-----


potrzebowałem, nie mogłem znaleźć, napisałem

  1. <?php
  2.  
  3. function is_nip($nr)
  4. {
  5. if ($nr === NULL || empty($nr)) return false;
  6. $weights = array (6, 5, 7, 2, 3, 4, 5, 6, 7) ;
  7. if ( preg_match_all("/d/", $nr, $digits) )
  8. {
  9. $digits = $digits[0];
  10. if ( count($digits)-!= count($weights) ) return false;
  11. $ctrl_digit = (int) array_pop($digits);
  12. $all_sum  = (int) 0;
  13. foreach ( $digits as $digit )
  14. {
  15. $weight  = (int) current($weights);
  16. $all_sum += (int) $digit * $weight;
  17. next($weights);
  18. }
  19. $calc_ctrl = (int) ($all_sum % 11 == 10) ? 0 : $all_sum % 11;
  20. if ($calc_ctrl == $ctrl_digit) return true;
  21. } 
  22. return false; 
  23. }
  24. ?>


sprawdzilem na 1553 numerach NIP, tylko tyle posiadam i funkcjonuje ok.
ale człowiek omylne zwierze wiec uwagi, poprawki, sugestie, pytania bedą mile widziane.

użycie
Kod
sprawdza poprawność podanego numeru NIP
bool is_nip (string nr)


nie trzeba sie martwić o forme wpisywania numeru tzn: może byc XXX-XX-XX-XXX albo XXXXXXXXXX, albo jakikolwiek zestaw znaków zawierający jednak 10 cyfr

Ten post edytował ghostrider 11.11.2005, 13:59:46


--------------------
There are 10 types of people in the world:
-Those who understand binary, and those who don't...
There's no place like 127.0.0.1
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 13.08.2025 - 23:29