validates_zipcode 0.7.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/validates_zipcode/cldr_regex_collection.rb +7 -53
- data/lib/validates_zipcode/countries_without_postcodes.rb +58 -0
- data/lib/validates_zipcode/version.rb +1 -1
- data/lib/validates_zipcode/zipcode.rb +1 -1
- data/lib/validates_zipcode.rb +1 -0
- data/spec/spec_helper.rb +313 -952
- data/spec/validates_zipcode_spec.rb +22 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 54edf3d6ef31810f8bbbe4000041dd8ba5407d6b366ea6d473adc65c52437791
|
|
4
|
+
data.tar.gz: 9de40d5361aaedc8a1737cc7153f503348f6c3c7225b1a08e2428db02680cdb5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 92e8653247badf47c41e9d239bdb8cd179056dddf1ccbabd6c0e2a8fe41b1e026712cb158bcb48f619c06ee5b9acd31e56ba224b25fbb1e656085688ef32a13f
|
|
7
|
+
data.tar.gz: 65700765af47967734ae4d7b8d936451cd394d950665fb0dcfe1f52ce18f243334b047db6a4f7b9587d3e65628c67985dc39a4328234e4a08258965a3641a4d4
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
## Unreleased
|
|
6
6
|
|
|
7
|
+
## 0.8.0
|
|
8
|
+
|
|
9
|
+
**Heads up:** This release changes which postcodes pass for some countries. The 50 countries without a postal system, such as Qatar (QA) and Côte d'Ivoire (CI), now accept any value, blank included; before, most of them required at least three letters or digits. Somalia (SO), Tonga (TO) and the US Minor Outlying Islands (UM) now accept blank or a well-formed code only, where they used to accept any three letters or digits.
|
|
10
|
+
|
|
11
|
+
- Document and consistently handle 50 countries with no postal codes, such as Qatar and Côte d'Ivoire. Thanks to ~ @johncurtislynch
|
|
12
|
+
- Update or add regexes for the following countries with optional postal codes: Somalia, Tonga, and the US Minor Outlying Islands. Thanks to ~ @johncurtislynch
|
|
13
|
+
- Standardize `nil` handling in postal code validator between countries with no regexes and countries with a regex that allows empty codes. This also fixes an issue where `ValidatesZipcode.valid?(96898, 'US')` would raise `TypeError`. Thanks to ~ @johncurtislynch
|
|
14
|
+
- Accept the current postcode formats of Iran (IR, 10 digits such as `11936-12345`), Taiwan (TW, 3+3 digits such as `106314`) and Vietnam (VN, 5 digits such as `70010`). Older forms stay valid. Thanks to ~ @bardrop
|
|
15
|
+
|
|
7
16
|
## 0.7.1
|
|
8
17
|
|
|
9
18
|
- Fix the United Kingdom (GB, UK) postcode pattern to anchor both alternatives. `\A` only applied to `GIR 0AA` and `\z` only to the regular form, so strings like `hello SW1A 2AA` or `GIR 0AA, London` were accepted — fixes #76. Thanks to ~ @bardrop
|
|
@@ -104,7 +104,6 @@ module ValidatesZipcode
|
|
|
104
104
|
ZM: /\A\d{5}\z/,
|
|
105
105
|
AS: /\A96799\z/,
|
|
106
106
|
CC: /\A6799\z/,
|
|
107
|
-
CK: /\A\d{4}\z/,
|
|
108
107
|
RS: /\A\d{5}\z/,
|
|
109
108
|
CS: /\A\d{5}\z/,
|
|
110
109
|
YU: /\A\d{5}\z/,
|
|
@@ -142,53 +141,26 @@ module ValidatesZipcode
|
|
|
142
141
|
WF: /\A986\d{2}\z/,
|
|
143
142
|
XK: /\A\d{5}\z/,
|
|
144
143
|
YT: /\A976\d{2}\z/,
|
|
145
|
-
# NOTE: UAE has no postal codes
|
|
146
|
-
# https://github.com/dgilperez/validates_zipcode/issues/28
|
|
147
|
-
# AE: /\A([A-Z\d\s]){3,}\z/i,
|
|
148
144
|
AF: /\A\d{4}\z/,
|
|
149
145
|
AL: /\A\d{4}\z/,
|
|
150
|
-
AG: /\A([A-Z\d\s]){3,}\z/i,
|
|
151
|
-
AO: /\A([A-Z\d\s]){3,}\z/i,
|
|
152
146
|
AZ: /\A(AZ ?)?\d{4}\z/i,
|
|
153
|
-
BF: /\A([A-Z\d\s]){3,}\z/i,
|
|
154
|
-
BI: /\A([A-Z\d\s]){3,}\z/i,
|
|
155
|
-
BS: /\A([A-Z\d\s]){3,}\z/i,
|
|
156
|
-
BZ: /\A([A-Z\d\s]){3,}\z/i,
|
|
157
147
|
BR: /\A\d{5}(-?\d{3})\z/,
|
|
158
|
-
BJ: /\A([A-Z\d\s]){3,}\z/i,
|
|
159
148
|
BT: /\A\d{5}\z/,
|
|
160
|
-
BQ: /\A([A-Z\d\s]){3,}\z/i,
|
|
161
|
-
# NOTE: Bolivia has no postal codes
|
|
162
|
-
# BO: /\A\d{4}\z/,
|
|
163
|
-
BW: /\A([A-Z\d\s]){3,}\z/i,
|
|
164
|
-
CF: /\A([A-Z\d\s]){3,}\z/i,
|
|
165
|
-
CG: /\A([A-Z\d\s]){3,}\z/i,
|
|
166
|
-
CI: /\A([A-Z\d\s]){3,}\z/i,
|
|
167
|
-
# NOTE: Cameroon has no postal codes
|
|
168
|
-
# CM: /\A([A-Z\d]){3,7}\z/i,
|
|
169
149
|
CO: /\A([A-Z\d\s]){3,}\z/i,
|
|
170
150
|
CR: /\A\d{5}\z/,
|
|
171
151
|
CU: /\A\d{5}\z/,
|
|
172
|
-
KM: /\A([A-Z\d\s]){3,}\z/i,
|
|
173
152
|
DJ: /\A([A-Z\d\s]){3,}\z/i,
|
|
174
|
-
DM: /\A([A-Z\d\s]){3,}\z/i,
|
|
175
153
|
EG: /\A([A-Z\d\s]){3,}\z/i,
|
|
176
|
-
GQ: /\A([A-Z\d\s]){3,}\z/i,
|
|
177
154
|
EL: /\A\d{5}\z/,
|
|
178
|
-
ER: /\A([A-Z\d\s]){3,}\z/i,
|
|
179
|
-
FJ: /\A([A-Z\d\s]){3,}\z/i,
|
|
180
155
|
FR: /\A\d{5}\z/,
|
|
181
|
-
GA: /\A\d{4}\z/,
|
|
182
|
-
GD: /\A([A-Z\d\s]){3,}\z/i,
|
|
183
156
|
GH: /\A([A-Z\d\s]){3,}\z/i,
|
|
184
|
-
GM: /\A([A-Z\d\s]){3,}\z/i,
|
|
185
157
|
GN: /\A([A-Z\d\s]){3,}\z/i,
|
|
186
158
|
GI: /\A(GX11 ?1AA)\z/i,
|
|
187
159
|
GR: /\A\d{3} ?\d{2}\z/,
|
|
188
160
|
GY: /\A([A-Z\d\s]){3,}\z/i,
|
|
189
161
|
HN: /\A([A-Z]{2}|\d{1})\d{4}\z/i,
|
|
190
162
|
IO: /\A\d{5}\z/,
|
|
191
|
-
IR: /\A\d{5}
|
|
163
|
+
IR: /\A\d{5}(-?\d{5})?\z/,
|
|
192
164
|
JP: /\A\d{3}-?\d{4}\z/,
|
|
193
165
|
# Jamaica has no postcode system.However, for Kingston, there are one- and two-digit sector codes.
|
|
194
166
|
# On February 12, 2007 it was announced: "POST CODE PROJECT SUSPENDED INDEFINITELY"
|
|
@@ -196,17 +168,14 @@ module ValidatesZipcode
|
|
|
196
168
|
JM: /\A((JM(DCN|CHR|AKN|DMR|BPD|AAW|CAN|ACE|DEH|CJS|BMY|BTS|CTY|DWD)(0[1-9]|[1-2]\d))|\d{1,2})?\z/i,
|
|
197
169
|
KI: /\AKI0[1-3]\d{2}\z/i,
|
|
198
170
|
KN: /\AKN ?\d{4}\z/i,
|
|
199
|
-
KP: /\A([A-Z\d\s]){3,8}\z/i,
|
|
200
171
|
LI: /\A\d{4}\z/,
|
|
201
172
|
LV: /\A(LV[- ]?)?\d{4}\z/i,
|
|
202
|
-
LY: /\A\d{5}\z/,
|
|
203
173
|
LT: /\A(LT[- ]?)?\d{5}\z/i,
|
|
204
174
|
LC: /\A([A-Z\d\s]){3,}\z/i,
|
|
205
175
|
MC: /\A\d{5}\z/,
|
|
206
176
|
MD: /\A(MD[- ]?)?\d{4}\z/i,
|
|
207
177
|
ME: /\A([A-Z\d\s]){3,}\z/i,
|
|
208
178
|
MH: /\A\d{5}\z/,
|
|
209
|
-
MR: /\A([A-Z\d\s]){3,}\z/i,
|
|
210
179
|
MM: /\A([A-Z\d\s]){3,}\z/i,
|
|
211
180
|
MW: /\A([A-Z\d\s]){3,}\z/i,
|
|
212
181
|
MZ: /\A\d{4}\z/,
|
|
@@ -217,37 +186,22 @@ module ValidatesZipcode
|
|
|
217
186
|
PS: /\A\d{3}\z/,
|
|
218
187
|
PA: /\A\d{4}\z/,
|
|
219
188
|
PE: /\A\d{5}\z/,
|
|
220
|
-
QA: /\A([A-Z\d\s]){3,}\z/i,
|
|
221
|
-
RW: /\A([A-Z\d\s]){3,}\z/i,
|
|
222
|
-
SC: /\A([A-Z\d\s]){3,}\z/i,
|
|
223
189
|
SE: /\A\d{3} ?\d{2}\z/,
|
|
224
190
|
SK: /\A[089]\d{2} ?\d{2}\z/,
|
|
225
|
-
|
|
226
|
-
SB: /\A([A-Z\d\s]){3,}\z/i,
|
|
227
|
-
SR: /\A([A-Z\d\s]){3,}\z/i,
|
|
228
|
-
SO: /\A([A-Z\d\s]){3,}\z/i,
|
|
191
|
+
SO: /\A(?:[A-Z]{2} ?\d{5})?\z/i,
|
|
229
192
|
SV: /\A([A-Z\d\s]){3,}\z/i,
|
|
230
193
|
SD: /\A\d{5}\z/,
|
|
231
|
-
|
|
232
|
-
SY: /\A([A-Z\d\s]){3,}\z/i,
|
|
233
|
-
SS: /\A\d{5}\z/,
|
|
234
|
-
TD: /\A\d{5}\z/,
|
|
235
|
-
TG: /\A([A-Z\d\s]){3,}\z/i,
|
|
236
|
-
TO: /\A([A-Z\d\s]){3,}\z/i,
|
|
194
|
+
TO: /\A(?:(?:PC ?)?[1-6]\d{8})?\z/i,
|
|
237
195
|
TZ: /\A([A-Z\d\s]){3,}\z/i,
|
|
238
196
|
TT: /\A\d{6}\z/,
|
|
239
|
-
TW: /\A\d{3}(\d{2})?\z/,
|
|
240
|
-
|
|
241
|
-
UM: /\A([A-Z\d\s]){3,}\z/i,
|
|
197
|
+
TW: /\A\d{3}(\d{2,3})?\z/,
|
|
198
|
+
UM: /\A(?:\d{5}(?:[ -]\d{4})?)?\z/,
|
|
242
199
|
UY: /\A([A-Z\d\s]){3,}\z/i,
|
|
243
200
|
VC: /\A(VC)\d{4}\z/i,
|
|
244
201
|
VI: /\A\d{5}\z/,
|
|
245
202
|
VG: /\A([A-Z\d\s]){3,}\z/i,
|
|
246
|
-
VN: /\A\d{6}\z/,
|
|
247
|
-
|
|
248
|
-
WS: /\A([A-Z\d\s]){3,}\z/i,
|
|
249
|
-
YE: /\A([A-Z\d\s]){3,}\z/i,
|
|
250
|
-
ZW: /\A([A-Z\d\s]){3,}\z/i
|
|
203
|
+
VN: /\A\d{5,6}\z/,
|
|
204
|
+
WS: /\A([A-Z\d\s]){3,}\z/i
|
|
251
205
|
}.freeze
|
|
252
206
|
|
|
253
207
|
def regexp_for_country_alpha2(alpha2)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ValidatesZipcode
|
|
4
|
+
module CldrRegexpCollection
|
|
5
|
+
COUNTRIES_WITHOUT_POSTCODES = {
|
|
6
|
+
AE: 'United Arab Emirates',
|
|
7
|
+
AG: 'Antigua and Barbuda',
|
|
8
|
+
AO: 'Angola',
|
|
9
|
+
AQ: 'Antarctica',
|
|
10
|
+
AW: 'Aruba',
|
|
11
|
+
BF: 'Burkina Faso',
|
|
12
|
+
BI: 'Burundi',
|
|
13
|
+
BJ: 'Benin',
|
|
14
|
+
BO: 'Bolivia',
|
|
15
|
+
BQ: 'Bonaire, Sint Eustatius and Saba',
|
|
16
|
+
BS: 'Bahamas',
|
|
17
|
+
BV: 'Bouvet Island',
|
|
18
|
+
BW: 'Botswana',
|
|
19
|
+
BZ: 'Belize',
|
|
20
|
+
CF: 'Central African Republic',
|
|
21
|
+
CG: 'Congo',
|
|
22
|
+
CI: 'Côte d\'Ivoire',
|
|
23
|
+
CK: 'Cook Islands',
|
|
24
|
+
CM: 'Cameroon',
|
|
25
|
+
CW: 'Curaçao',
|
|
26
|
+
DM: 'Dominica',
|
|
27
|
+
ER: 'Eritrea',
|
|
28
|
+
FJ: 'Fiji',
|
|
29
|
+
GA: 'Gabon',
|
|
30
|
+
GD: 'Grenada',
|
|
31
|
+
GM: 'Gambia',
|
|
32
|
+
GQ: 'Equatorial Guinea',
|
|
33
|
+
KM: 'Comoros',
|
|
34
|
+
KP: 'North Korea',
|
|
35
|
+
LY: 'Libya',
|
|
36
|
+
ML: 'Mali',
|
|
37
|
+
MR: 'Mauritania',
|
|
38
|
+
QA: 'Qatar',
|
|
39
|
+
RW: 'Rwanda',
|
|
40
|
+
SB: 'Solomon Islands',
|
|
41
|
+
SC: 'Seychelles',
|
|
42
|
+
SL: 'Sierra Leone',
|
|
43
|
+
SR: 'Suriname',
|
|
44
|
+
SS: 'South Sudan',
|
|
45
|
+
ST: 'Sao Tomé and Principe',
|
|
46
|
+
SX: 'Sint Maarten (Dutch part)',
|
|
47
|
+
SY: 'Syria',
|
|
48
|
+
TD: 'Chad',
|
|
49
|
+
TG: 'Togo',
|
|
50
|
+
TK: 'Tokelau',
|
|
51
|
+
TV: 'Tuvalu',
|
|
52
|
+
UG: 'Uganda',
|
|
53
|
+
VU: 'Vanuatu',
|
|
54
|
+
YE: 'Yemen',
|
|
55
|
+
ZW: 'Zimbabwe'
|
|
56
|
+
}.freeze
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -15,7 +15,7 @@ module ValidatesZipcode
|
|
|
15
15
|
return false unless valid_country_alpha2?
|
|
16
16
|
return true unless regexp
|
|
17
17
|
|
|
18
|
-
zipcode = @format ? formatted_zip : @zipcode
|
|
18
|
+
zipcode = @format ? formatted_zip : @zipcode.to_s
|
|
19
19
|
!!(regexp =~ zipcode)
|
|
20
20
|
end
|
|
21
21
|
alias_method :validate, :valid?
|
data/lib/validates_zipcode.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
require 'validates_zipcode/railtie' if defined?(Rails)
|
|
3
3
|
require 'validates_zipcode/cldr_regex_collection'
|
|
4
|
+
require 'validates_zipcode/countries_without_postcodes'
|
|
4
5
|
require 'validates_zipcode/invalid_zipcode_error'
|
|
5
6
|
require 'validates_zipcode/validator'
|
|
6
7
|
require 'validates_zipcode/helper_methods'
|