Cake\Localized\Validation\UaValidation::postal PHP Метод

postal() публичный статический Метод

Checks a postal (zip) code for Ukraine
public static postal ( string $check ) : boolean
$check string The value to check.
Результат boolean Success.
    public static function postal($check)
    {
        $pattern = '/^(0[1-9][0-9][0-9][0-9]|1[0-9][0-9][0-9][0-9]|2[0-9][0-9][0-9][0-9]|3[0-9][0-9][0-9][0-9]|4[0-9][0-9][0-9][0-9]|5[0-9][0-9][0-9][0-9]|6[0-9][0-9][0-9][0-9]|7[0-9][0-9][0-9][0-9]|8[0-9][0-9][0-9][0-9]|9[0-9][0-9][0-9][0-9]|)$/';
        return (bool) preg_match($pattern, $check);
    }

Usage Example

Пример #1
0
 /**
  * test the postal method of UaValidation
  *
  * @return void
  */
 public function testPostal()
 {
     $this->assertTrue(UaValidation::postal('85111'));
     $this->assertTrue(UaValidation::postal('01996'));
     $this->assertTrue(UaValidation::postal('65000'));
     $this->assertFalse(UaValidation::postal('019962'));
     $this->assertFalse(UaValidation::postal('019961'));
     $this->assertFalse(UaValidation::postal('0199'));
 }