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

postal() public static method

Checks a postal code for Canada.
public static postal ( string $check ) : boolean
$check string The value to check.
return boolean Success.
    public static function postal($check)
    {
        $pattern = '/\\A\\b[ABCEGHJKLMNPRSTVXY][0-9][A-Z] [0-9][A-Z][0-9]\\b\\z/i';
        return (bool) preg_match($pattern, $check);
    }

Usage Example

Beispiel #1
0
 /**
  * test the postal method of CaValidation
  *
  * @return void
  */
 public function testPostal()
 {
     $this->assertTrue(CaValidation::postal('L4W 1S2'));
     $this->assertFalse(CaValidation::postal('LI4 SOC'));
 }