Skip to content

Commit 04601f9

Browse files
committed
Add support for the Canary Islands
1 parent acd390f commit 04601f9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/PostalCodeValidator.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
class PostalCodeValidator
66
{
7+
/**
8+
* The country codes that are aliases for other country codes.
9+
*/
10+
private const ALIASES = [
11+
'IC' => 'ES',
12+
];
13+
714
/**
815
* The matching patterns.
916
*
@@ -101,6 +108,10 @@ public function patternFor(string $countryCode): ?string
101108
{
102109
$countryCode = strtoupper($countryCode);
103110

111+
if (array_key_exists($countryCode, self::ALIASES)) {
112+
$countryCode = self::ALIASES[$countryCode];
113+
}
114+
104115
return $this->patternOverrides[$countryCode]
105116
?? $this->patterns[$countryCode]
106117
?? null;
@@ -117,6 +128,7 @@ public function supports(string $countryCode): bool
117128
$countryCode = strtoupper($countryCode);
118129

119130
return array_key_exists($countryCode, $this->patternOverrides)
120-
|| array_key_exists($countryCode, $this->patterns);
131+
|| array_key_exists($countryCode, $this->patterns)
132+
|| array_key_exists($countryCode, self::ALIASES);
121133
}
122134
}

tests/Unit/PostalCodeValidatorTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ protected function setUp(): void
3939
);
4040
}
4141

42+
/**
43+
* @link https://github.com/axlon/laravel-postal-code-validation/issues/35
44+
*/
45+
public function testCanaryIslands(): void
46+
{
47+
$this->assertTrue($this->validator->passes('IC', '38580'));
48+
}
49+
4250
/**
4351
* Test if the shipped examples pass validation.
4452
*

0 commit comments

Comments
 (0)