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

postal() public static method

Checks a postal code for the Lithuania.
public static postal ( string $check ) : boolean
$check string The value to check.
return boolean Success.
    public static function postal($check)
    {
        $pattern = '/^(lt)?[\\s-]?[\\d]{5}$/i';
        return (bool) preg_match($pattern, $check);
    }

Usage Example

Example #1
0
 /**
  * test the postal method of LtValidation
  *
  * @return void
  */
 public function testPostal()
 {
     $this->assertTrue(LtValidation::postal('89104'));
     $this->assertTrue(LtValidation::postal('LT-13089'));
     $this->assertTrue(LtValidation::postal('lt-13022'));
     $this->assertTrue(LtValidation::postal('Lt 13047'));
     $this->assertFalse(LtValidation::postal('111'));
     $this->assertFalse(LtValidation::postal('1111'));
     $this->assertFalse(LtValidation::postal('130896'));
     $this->assertFalse(LtValidation::postal('13089-333'));
     $this->assertFalse(LtValidation::postal('lu-55621'));
     $this->assertFalse(LtValidation::postal('LY-52147'));
     $this->assertFalse(LtValidation::postal('Nv 52125'));
 }