public static function postal($check) { $pattern = '/\\A\\b[0-9]{5}(?:-[0-9]{4})?\\b\\z/i'; return (bool) preg_match($pattern, $check); }
/** * test the postal method of UsValidation * * @return void */ public function testPostal() { $this->assertTrue(UsValidation::postal('89104')); $this->assertFalse(UsValidation::postal('111')); $this->assertFalse(UsValidation::postal('1111')); $this->assertFalse(UsValidation::postal('130896')); $this->assertFalse(UsValidation::postal('13089-33333')); $this->assertFalse(UsValidation::postal('13089-333')); $this->assertFalse(UsValidation::postal('13A89-4333')); $this->assertTrue(UsValidation::postal('13089-3333')); $this->assertFalse(UsValidation::postal('NV 89104')); }