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

postal() public static method

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

Usage Example

Beispiel #1
0
 /**
  * test the postal method of TwValidation
  *
  * @return void
  */
 public function testPostal()
 {
     $this->assertTrue(TwValidation::postal('235'));
     $this->assertTrue(TwValidation::postal('615'));
     $this->assertTrue(TwValidation::postal('10075'));
     $this->assertTrue(TwValidation::postal('71074'));
     $this->assertFalse(TwValidation::postal('085'));
 }