File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 44
55class 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}
Original file line number Diff line number Diff 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 *
You can’t perform that action at this time.
0 commit comments