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 4
4
5
5
class PostalCodeValidator
6
6
{
7
+ /**
8
+ * The country codes that are aliases for other country codes.
9
+ */
10
+ private const ALIASES = [
11
+ 'IC ' => 'ES ' ,
12
+ ];
13
+
7
14
/**
8
15
* The matching patterns.
9
16
*
@@ -101,6 +108,10 @@ public function patternFor(string $countryCode): ?string
101
108
{
102
109
$ countryCode = strtoupper ($ countryCode );
103
110
111
+ if (array_key_exists ($ countryCode , self ::ALIASES )) {
112
+ $ countryCode = self ::ALIASES [$ countryCode ];
113
+ }
114
+
104
115
return $ this ->patternOverrides [$ countryCode ]
105
116
?? $ this ->patterns [$ countryCode ]
106
117
?? null ;
@@ -117,6 +128,7 @@ public function supports(string $countryCode): bool
117
128
$ countryCode = strtoupper ($ countryCode );
118
129
119
130
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 );
121
133
}
122
134
}
Original file line number Diff line number Diff line change @@ -39,6 +39,14 @@ protected function setUp(): void
39
39
);
40
40
}
41
41
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
+
42
50
/**
43
51
* Test if the shipped examples pass validation.
44
52
*
You can’t perform that action at this time.
0 commit comments