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

postal() public static method

Checks a postal code for Spain.
public static postal ( string $check ) : boolean
$check string The value to check.
return boolean Success.
    public static function postal($check)
    {
        $pattern = '/^(5[0-2]|[0-4][0-9])[0-9]{3}$/';
        return (bool) preg_match($pattern, $check);
    }

Usage Example

Example #1
0
 /**
  * test the postal method of EsValidation
  *
  * @return void
  */
 public function testPostal()
 {
     $this->assertTrue(EsValidation::postal('02300'));
     $this->assertFalse(EsValidation::postal('2300'));
     $this->assertFalse(EsValidation::postal('230000'));
 }