public static function postal($check) { $pattern = '/^(0[1-46-9]\\d{3}|[1-357-9]\\d{4}|[4][0-24-9]\\d{3}|[6][013-9]\\d{3})$/'; return (bool) preg_match($pattern, $check); }
/** * test the postal method of DeValidation * according to wikipedia, some combinations are reserved and therefore not valid * https://de.wikipedia.org/wiki/Liste_der_Postleitregionen_in_Deutschland#F.C3.BCnfstelliges_System_seit_1993 * @return void */ public function testPostal() { $this->assertTrue(DeValidation::postal('51109')); // must have 5 digits $this->assertFalse(DeValidation::postal('1109')); $this->assertFalse(DeValidation::postal('051109')); $this->assertFalse(DeValidation::postal('00109')); $this->assertTrue(DeValidation::postal('01109')); $this->assertFalse(DeValidation::postal('05000')); $this->assertTrue(DeValidation::postal('06109')); $this->assertFalse(DeValidation::postal('43000')); $this->assertTrue(DeValidation::postal('44109')); $this->assertFalse(DeValidation::postal('62000')); $this->assertTrue(DeValidation::postal('63109')); }