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

postal() public static method

Checks a postal code for The United Kingdom
public static postal ( string $check ) : boolean
$check string The value to check.
return boolean Success.
    public static function postal($check)
    {
        $pattern = '/\\A\\b[A-Z]{1,2}[0-9][A-Z0-9]? [0-9][ABD-HJLNP-UW-Z]{2}\\b\\z/i';
        return (bool) preg_match($pattern, $check);
    }

Usage Example

Beispiel #1
0
 /**
  * test the postal method of GbValidation
  *
  * @return void
  */
 public function testPostal()
 {
     $this->assertTrue(GbValidation::postal('DT4 8PP'));
     $this->assertFalse(GbValidation::postal('DT4-8PP'));
 }