public static function postal($check) { $pattern = '/^\\d{5}$/'; if ((bool) preg_match($pattern, $check)) { $value = intval($check); return $value >= 1001 && $value <= 99138; } return false; }
/** * test the postal method of FrValidation * * @return void */ public function testPostal() { $this->assertTrue(FrValidation::postal('01001')); $this->assertTrue(FrValidation::postal('14000')); $this->assertTrue(FrValidation::postal('75001')); $this->assertTrue(FrValidation::postal('13200')); $this->assertTrue(FrValidation::postal('97500')); $this->assertTrue(FrValidation::postal('99138')); $this->assertFalse(FrValidation::postal('1400')); $this->assertFalse(FrValidation::postal('14 000')); $this->assertFalse(FrValidation::postal('00000')); $this->assertFalse(FrValidation::postal('01000')); $this->assertFalse(FrValidation::postal('99139')); }