jezeli chodzi o sama klase to mysle, ja rozbudowac o kolejne metody sprawdzajace nip, regon, pesel i troche innych rzeczy...
w chwili obecnej to ona ma nastepujaca postac:
<?php
class SprawdzanieDanych
{
// sprawdzany ciag
var $ciag;
// zmienna przechowujaca sume
var $suma;
// liczba kontrolna
var $liczba_kontrolna;
// tablica przechowujaca wagi dla poszczegolnych pozycji w sprawdzanym numerze
var $wagi;
// licznik petli
var $i;
/**
* @desc Kontruktor klasy
*/
function SprawdzanieDanych($ciag) {
$this->ciag = $ciag;
}
/**
* @desc Sprawdzenie poprawnosci adresu poczty elektronicznej
*
* @return bool
*/
function email() {
return preg_match('/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$/', $this->ciag); }
/**
* @desc Sprawdzenie poprawnosci kodu pocztowego
*
* @return bool
*/
function kodPocztowy() {
return preg_match('/^[0-9]{2}[-][0-9]{3}$/', $this->ciag); }
/**
* @desc Sprawdzanie poprawnosci numeru NIP wg. wzorca: xxx-xxx-xx-xx
*
* @return bool
*/
function nip() {
// sprawdzenie dopasowania do wzorca
if (!ereg('^[0-9]{3}-[0-9]{3}-[0-9]{2}-[0-9]{2}$', $this->ciag)) return 0;
$this->wagi = array(6
, 5
, 7
, 2
, 3
, 4
, 5
, 6
, 7
);
$this->suma = 0;
for ($this->i = 0; $this->i < count($this->wagi); $this->i++) $this->suma += substr($this->ciag, $this->i, 1
) * $this->wagi[$this->i];
if ( ($this->suma % 11
) == substr($this->ciag, 9
, 1
) ) return 1;
else
return 0;
}
/**
* @desc Sprawdzanie poprawnosci numeru REGON
*
* @return bool
*/
function regon() {
if (!ereg('^[0-9]{9}$', $this->ciag)) return 0;
$this->wagi = array(8
, 9
, 2
, 3
, 4
, 5
, 6
, 7
);
$this->suma = 0;
for ($this->i = 0; $this->i < count($this->wagi); $this->i++) $this->suma += substr($this->ciag, $this->i, 1
) * $this->wagi[$this->i];
if ( ($this->suma % 11
) == substr($this->ciag, 8
, 1
)) return 1;
elseif ( (($this->suma % 11
) == 10
) && (substr($this->ciag, 8
, 1
) == 0
) ) return 1;
else
return 0;
}
/**
* @desc Sprawdzanie poprawnosci numeru PESEL
*
* @return bool
*/
function pesel() {
if (!ereg('^[0-9]{11}$', $this->ciag)) return 0;
$this->wagi = array(1
, 3
, 7
, 9
, 1
, 3
, 7
, 9
, 1
, 3
);
$this->suma = 0;
for ($this->i = 0; $this->i < count($this->wagi); $this->i++) $this->suma += substr($this->ciag, $this->i, 1
) * $this->wagi[$this->i];
$this->liczba_kontrolna = 10 - ($this->suma % 10);
if ( ($this->liczba_kontrolna == 10
) && (substr($this->ciag, 10
, 1
) == 0
) ) return 1;
elseif ($this->liczba_kontrolna == substr($this->ciag, 10
, 1
)) return 1;
else
return 0;
}
}
?>