Cake\Localized\Validation\EsValidation::nie PHP Method

nie() public static method

Only checks the NIE type personId.
public static nie ( string $check ) : boolean
$check string The value to check.
return boolean Success.
    public static function nie($check)
    {
        if (!preg_match('/^([XYZ])([0-9]+)([A-Z]{1})$/', $check, $matches)) {
            return false;
        }
        array_shift($matches);
        list($first, $num, $letter) = $matches;
        $num = strtr($first, 'XYZ', '012') . $num;
        return $letter === static::$CODES[$num % 23];
    }

Usage Example

Example #1
0
 /**
  * Test the nie validation.
  *
  * @return void
  */
 public function testNie()
 {
     $this->assertTrue(EsValidation::nie('X2546874S'));
     $this->assertTrue(EsValidation::nie('Y2332323E'));
     $this->assertTrue(EsValidation::nie('Z2548769Y'));
     $this->assertFalse(EsValidation::nie('35489765Y'));
     $this->assertFalse(EsValidation::nie('123456'));
 }