Cake\Localized\Validation\RsValidation::personId PHP Method

personId() public static method

Checks Unique Master Citizen Numbers (JMBG) for Serbia.
public static personId ( string $check ) : boolean
$check string The value to check.
return boolean Success.
    public static function personId($check)
    {
        if (!preg_match('/^[0-9]{13}$/', $check)) {
            return false;
        }
        list($a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k, $l, $m) = str_split($check);
        $checksum = 11 - (7 * ($a + $g) + 6 * ($b + $h) + 5 * ($c + $i) + 4 * ($d + $j) + 3 * ($e + $k) + 2 * ($f + $l)) % 11;
        return $checksum == $m;
    }

Usage Example

Beispiel #1
0
 /**
  * test the jmbg method of RsValidation
  *
  * @return void
  */
 public function testPersonId()
 {
     $this->assertTrue(RsValidation::personId('1707017170007'));
     $this->assertFalse(RsValidation::personId('1707017170008'));
     $this->assertFalse(RsValidation::personId('170701717000'));
     $this->assertFalse(RsValidation::personId('A707017170007'));
 }