validates_zipcode 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/Rakefile +5 -0
- data/lib/validates_zipcode/cldr_regex_collection.rb +101 -1
- data/lib/validates_zipcode/version.rb +1 -1
- data/spec/validates_zipcode_spec.rb +24 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 952d9f9b375d3c93c0c71af3dfd9f6dcd6712693
|
4
|
+
data.tar.gz: 4be0f548de981b71b4e87ee2ec8bb377fb906431
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecdbe24c23bf5296fb45daf4fa6d35b9c60f9fa83bf4e9da3fc23b767ee329beefa14e66940e8ad99cd8ee0e889852b02946eda0c300ba44fd2fc7b786effe76
|
7
|
+
data.tar.gz: 6e9a17ced86e144d499d50f650422035c1ab439c6c70831561da45c739da061feabab53dc0f0c7bbb208fede7f20e5c5c5b466d5a74ac6ca5db86f8865e24662
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
# ValidatesZipcode [![Build Status](https://secure.travis-ci.org/dgilperez/validates_zipcode.png)](https://travis-ci.org/dgilperez/validates_zipcode) [![Code Climate](https://codeclimate.com/github/dgilperez/validates_zipcode/badges/gpa.svg)](https://codeclimate.com/github/dgilperez/validates_zipcode) [![Gem Version](https://badge.fury.io/rb/validates_zipcode.svg)](http://badge.fury.io/rb/validates_zipcode)
|
1
|
+
# ValidatesZipcode [![Build Status](https://secure.travis-ci.org/dgilperez/validates_zipcode.png)](https://travis-ci.org/dgilperez/validates_zipcode) [![Code Climate](https://codeclimate.com/github/dgilperez/validates_zipcode/badges/gpa.svg)](https://codeclimate.com/github/dgilperez/validates_zipcode) [![Gem Version](https://badge.fury.io/rb/validates_zipcode.svg)](http://badge.fury.io/rb/validates_zipcode) [![security](https://hakiri.io/github/dgilperez/validates_zipcode/master.svg)](https://hakiri.io/github/dgilperez/validates_zipcode/master)
|
2
2
|
|
3
3
|
Add zipcode validation support to Rails (ActiveModel), considering different zipcode country formats.
|
4
4
|
|
5
|
-
``ValidatesZipcode`` currently support **
|
5
|
+
``ValidatesZipcode`` currently support **259 countries**. Regex data taken from several sources, being the main source the [CLDR](common/supplemental/postalCodeData.xml) database (around 159). Any other country's zipcode will validate without errors.
|
6
6
|
|
7
7
|
``ValidatesZipcode`` works for Rails 3 & 4 and Ruby >= 1.9.3.
|
8
8
|
|
data/Rakefile
CHANGED
@@ -162,7 +162,107 @@ module ValidatesZipcode
|
|
162
162
|
TC: /\ATKCA 1ZZ\z/,
|
163
163
|
WF: /\A986\d{2}\z/,
|
164
164
|
XK: /\A\d{5}\z/,
|
165
|
-
YT: /\A976\d{2}\z
|
165
|
+
YT: /\A976\d{2}\z/,
|
166
|
+
AE: /\A([a-zA-Z\d\s]){3,}\z/,
|
167
|
+
AF: /\A\d{4}\z/,
|
168
|
+
AL: /\A\d{4}\z/,
|
169
|
+
AG: /\A([a-zA-Z\d\s]){3,}\z/,
|
170
|
+
AO: /\A([a-zA-Z\d\s]){3,}\z/,
|
171
|
+
AZ: /\A([a-zA-Z\d\s]){3,}\z/,
|
172
|
+
BF: /\A([a-zA-Z\d\s]){3,}\z/,
|
173
|
+
BI: /\A([a-zA-Z\d\s]){3,}\z/,
|
174
|
+
BS: /\A([a-zA-Z\d\s]){3,}\z/,
|
175
|
+
BZ: /\A([a-zA-Z\d\s]){3,}\z/,
|
176
|
+
BR: /\A\d{4}[a-zA-Z][\- | [ ]]\d{2}[a-zA-Z]\z/,
|
177
|
+
BJ: /\A([a-zA-Z\d\s]){3,}\z/,
|
178
|
+
BT: /\A\d{5}\z/,
|
179
|
+
BQ: /\A([a-zA-Z\d\s]){3,}\z/,
|
180
|
+
BO: /\A\d{4}\z/,
|
181
|
+
BW: /\A([a-zA-Z\d\s]){3,}\z/,
|
182
|
+
CF: /\A([a-zA-Z\d\s]){3,}\z/,
|
183
|
+
CG: /\A([a-zA-Z\d\s]){3,}\z/,
|
184
|
+
CI: /\A([a-zA-Z\d\s]){3,}\z/,
|
185
|
+
CM: /\A([a-zA-Z\d]){3,7}\z/,
|
186
|
+
CO: /\A([a-zA-Z\d\s]){3,}\z/,
|
187
|
+
CR: /\A\d{5}\z/,
|
188
|
+
CU: /\A\d{5}\z/,
|
189
|
+
KM: /\A([a-zA-Z\d\s]){3,}\z/,
|
190
|
+
DJ: /\A([a-zA-Z\d\s]){3,}\z/,
|
191
|
+
DM: /\A([a-zA-Z\d\s]){3,}\z/,
|
192
|
+
EG: /\A([a-zA-Z\d\s]){3,}\z/,
|
193
|
+
GQ: /\A([a-zA-Z\d\s]){3,}\z/,
|
194
|
+
EL: /\A\d{5}\z/,
|
195
|
+
ER: /\A([a-zA-Z\d\s]){3,}\z/,
|
196
|
+
FJ: /\A([a-zA-Z\d\s]){3,}\z/,
|
197
|
+
FR: /\A\d{5}\z/,
|
198
|
+
GA: /\A\d{2}\z/,
|
199
|
+
GD: /\A([a-zA-Z\d\s]){3,}\z/,
|
200
|
+
GH: /\A([a-zA-Z\d\s]){3,}\z/,
|
201
|
+
GM: /\A([a-zA-Z\d\s]){3,}\z/,
|
202
|
+
GN: /\A([a-zA-Z\d\s]){3,}\z/,
|
203
|
+
GI: /\A(GX11 1AA)\z/,
|
204
|
+
GR: /\A\d{3}([ ]\d{2})\z/,
|
205
|
+
GY: /\A([a-zA-Z\d\s]){3,}\z/,
|
206
|
+
HN: /\A(([a-zA-Z]){2}|\d{2})\d{4}\z/,
|
207
|
+
IO: /\A\d{5}\z/,
|
208
|
+
IR: /\A\d{5}\z/,
|
209
|
+
JP: /\A\d{7}\z/,
|
210
|
+
JM: /\A(JM)[A-Z]{3}\d{2}\z/,
|
211
|
+
KI: /\A([a-zA-Z\d\s]){3,}\z/,
|
212
|
+
KN: /\A([a-zA-Z\d\s]){3,8}\z/,
|
213
|
+
KP: /\A([a-zA-Z\d\s]){3,8}\z/,
|
214
|
+
LI: /\A\d{4}\z/,
|
215
|
+
LV: /\A([a-zA-Z]|\d){3,8}\z/,
|
216
|
+
LY: /\A\d{5}\z/,
|
217
|
+
LT: /\A([a-zA-Z]){2}(-)\d{4}\z/,
|
218
|
+
LC: /\A([a-zA-Z\d\s]){3,}\z/,
|
219
|
+
MC: /\A\d{5}\z/,
|
220
|
+
MD: /\A(([a-zA-Z]){2})(|\s)\d{4}\z/,
|
221
|
+
ME: /\A([a-zA-Z\d\s]){3,}\z/,
|
222
|
+
MH: /\A\d{5}\z/,
|
223
|
+
MR: /\A([a-zA-Z\d\s]){3,}\z/,
|
224
|
+
MM: /\A([a-zA-Z\d\s]){3,}\z/,
|
225
|
+
MW: /\A([a-zA-Z\d\s]){3,}\z/,
|
226
|
+
MZ: /\A\d{4}\z/,
|
227
|
+
NA: /\A\d{5}\z/,
|
228
|
+
NP: /\A\d{6}\z/,
|
229
|
+
NR: /\A([a-zA-Z\d\s]){3,}\z/,
|
230
|
+
PT: /\A\d{8}\z/,
|
231
|
+
PS: /\A\d{3}\z/,
|
232
|
+
PA: /\A\d{6}\z/,
|
233
|
+
PE: /\A\d{5}\z/,
|
234
|
+
QA: /\A([a-zA-Z\d\s]){3,}\z/,
|
235
|
+
RW: /\A([a-zA-Z\d\s]){3,}\z/,
|
236
|
+
SC: /\A([a-zA-Z\d\s]){3,}\z/,
|
237
|
+
SE: /\A\d{3}[ ]\d{2}\z/,
|
238
|
+
SK: /\A\d{3}[ ]\d{2}\z/,
|
239
|
+
SL: /\A([a-zA-Z\d\s]){3,}\z/,
|
240
|
+
SB: /\A([a-zA-Z\d\s]){3,}\z/,
|
241
|
+
SR: /\A([a-zA-Z\d\s]){3,}\z/,
|
242
|
+
SO: /\A([a-zA-Z\d\s]){3,}\z/,
|
243
|
+
SV: /\A([a-zA-Z\d\s]){3,}\z/,
|
244
|
+
SD: /\A\d{5}\z/,
|
245
|
+
ST: /\A([a-zA-Z\d\s]){3,}\z/,
|
246
|
+
SY: /\A([a-zA-Z\d\s]){3,}\z/,
|
247
|
+
SS: /\A\d{5}\z/,
|
248
|
+
TD: /\A\d{5}\z/,
|
249
|
+
TG: /\A([a-zA-Z\d\s]){3,}\z/,
|
250
|
+
TO: /\A([a-zA-Z\d\s]){3,}\z/,
|
251
|
+
TZ: /\A([a-zA-Z\d\s]){3,}\z/,
|
252
|
+
TT: /\A\d{6}\z/,
|
253
|
+
TW: /\A\d{3}\z/,
|
254
|
+
UK: /\A([A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA)\z/,
|
255
|
+
UG: /\A([a-zA-Z\d\s]){3,}\z/,
|
256
|
+
UM: /\A([a-zA-Z\d\s]){3,}\z/,
|
257
|
+
UY: /\A([a-zA-Z\d\s]){3,}\z/,
|
258
|
+
VC: /\A(VC)\d{4}\z/,
|
259
|
+
VI: /\A\d{5}\z/,
|
260
|
+
VG: /\A([a-zA-Z\d\s]){3,}\z/,
|
261
|
+
VN: /\A\d{6}\z/,
|
262
|
+
VU: /\A([a-zA-Z\d\s]){3,}\z/,
|
263
|
+
WS: /\A([a-zA-Z\d\s]){3,}\z/,
|
264
|
+
YE: /\A([a-zA-Z\d\s]){3,}\z/,
|
265
|
+
ZW: /\A([a-zA-Z\d\s]){3,}\z/
|
166
266
|
}
|
167
267
|
|
168
268
|
def regexp_for_country_alpha2(alpha2)
|
@@ -114,6 +114,30 @@ describe ValidatesZipcode, '#validate_each' do
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
+
context 'Lithuania' do
|
118
|
+
it 'validates with a valid zipcode' do
|
119
|
+
record = build_record('LT-0110', 'LT')
|
120
|
+
zipcode_should_be_valid(record)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'does not validate with an invalid zipcode' do
|
124
|
+
record = build_record('21006', 'LT')
|
125
|
+
zipcode_should_be_invalid(record)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'Moldova' do
|
130
|
+
it 'validates with a valid zipcode' do
|
131
|
+
record = build_record('MD2001', 'MD')
|
132
|
+
zipcode_should_be_valid(record)
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'does not validate with an invalid zipcode' do
|
136
|
+
record = build_record('MD-2100', 'MD')
|
137
|
+
zipcode_should_be_invalid(record)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
117
141
|
def zipcode_should_be_valid(record)
|
118
142
|
ValidatesZipcode::Validator.new(attributes: :zipcode).validate(record)
|
119
143
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validates_zipcode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Gil
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
112
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.4.6
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: Localizable zipcode validation for Rails.
|