public static function validate($zipcode, $country = null)
{
$zipcode = trim($zipcode);
$country = trim($country);
if (empty($zipcode) || empty($country)) {
return false;
}
$country = strtoupper($country);
if (!isset(self::$patterns[$country])) {
throw new \InvalidArgumentException("ERROR: The zipcode validator for {$country} does not exists yet: feel free to add it.");
}
return (bool) preg_match('/^(' . self::$patterns[$country] . ')$/', $zipcode);
}
public function testEmptyValuesByCountry() { foreach (ZipCode::getAvailableCountries() as $country) { foreach ($this->getEmptyValues() as $value) { $this->assertFalse(ZipCode::validate($value, $country), 'Empty value should be invalid.'); } } }