diff --git a/src/PostalCodeValidator.php b/src/PostalCodeValidator.php index 75f90df..2c83a10 100644 --- a/src/PostalCodeValidator.php +++ b/src/PostalCodeValidator.php @@ -4,6 +4,13 @@ class PostalCodeValidator { + /** + * The country codes that are aliases for other country codes. + */ + private const ALIASES = [ + 'IC' => 'ES', + ]; + /** * The matching patterns. * @@ -101,6 +108,10 @@ public function patternFor(string $countryCode): ?string { $countryCode = strtoupper($countryCode); + if (array_key_exists($countryCode, self::ALIASES)) { + $countryCode = self::ALIASES[$countryCode]; + } + return $this->patternOverrides[$countryCode] ?? $this->patterns[$countryCode] ?? null; @@ -117,6 +128,7 @@ public function supports(string $countryCode): bool $countryCode = strtoupper($countryCode); return array_key_exists($countryCode, $this->patternOverrides) - || array_key_exists($countryCode, $this->patterns); + || array_key_exists($countryCode, $this->patterns) + || array_key_exists($countryCode, self::ALIASES); } } diff --git a/tests/Unit/PostalCodeValidatorTest.php b/tests/Unit/PostalCodeValidatorTest.php index 3b5b77e..ff301c4 100644 --- a/tests/Unit/PostalCodeValidatorTest.php +++ b/tests/Unit/PostalCodeValidatorTest.php @@ -39,6 +39,14 @@ protected function setUp(): void ); } + /** + * @link https://github.com/axlon/laravel-postal-code-validation/issues/35 + */ + public function testCanaryIslands(): void + { + $this->assertTrue($this->validator->passes('IC', '38580')); + } + /** * Test if the shipped examples pass validation. *