Skip to content
This repository was archived by the owner on May 27, 2021. It is now read-only.

Commit 713b5cf

Browse files
committed
Added zip code validators for Austria and Switzerland. Improved zip code validator for Germany. Added unit tests Austria, Germany and Switzerland. Updated translations.
1 parent 9458868 commit 713b5cf

File tree

8 files changed

+182
-22
lines changed

8 files changed

+182
-22
lines changed

dist/css/bootstrapValidator.min.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* BootstrapValidator (http://bootstrapvalidator.com)
33
* The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
44
*
5-
* @version v0.5.3-dev, built on 2014-11-03 3:09:43 PM
5+
* @version v0.5.3-dev, built on 2014-11-03 12:37:06 PM
66
* @author https://twitter.com/nghuuphuoc
77
* @copyright (c) 2013 - 2014 Nguyen Huu Phuoc
88
* @license MIT

dist/js/bootstrapValidator.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* BootstrapValidator (http://bootstrapvalidator.com)
33
* The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
44
*
5-
* @version v0.5.3-dev, built on 2014-11-03 3:09:43 PM
5+
* @version v0.5.3-dev, built on 2014-11-03 12:37:06 PM
66
* @author https://twitter.com/nghuuphuoc
77
* @copyright (c) 2013 - 2014 Nguyen Huu Phuoc
88
* @license MIT
@@ -8006,8 +8006,10 @@ if (typeof jQuery === 'undefined') {
80068006
countryNotSupported: 'The country code %s is not supported',
80078007
country: 'Please enter a valid postal code in %s',
80088008
countries: {
8009+
AT: 'Austria',
80098010
BR: 'Brazil',
80108011
CA: 'Canada',
8012+
CH: 'Switzerland',
80118013
CZ: 'Czech Republic',
80128014
DE: 'Germany',
80138015
DK: 'Denmark',
@@ -8033,7 +8035,7 @@ if (typeof jQuery === 'undefined') {
80338035
country: 'country'
80348036
},
80358037

8036-
COUNTRY_CODES: ['BR', 'CA', 'CZ', 'DE', 'DK', 'FR', 'GB', 'IE', 'IT', 'MA', 'NL', 'PT', 'RO', 'RU', 'SE', 'SG', 'SK', 'US'],
8038+
COUNTRY_CODES: [ 'AT', 'BR', 'CA', 'CH', 'CZ', 'DE', 'DK', 'FR', 'GB', 'IE', 'IT', 'MA', 'NL', 'PT', 'RO', 'RU', 'SE', 'SG', 'SK', 'US'],
80378039

80388040
/**
80398041
* Return true if and only if the input value is a valid country zip code
@@ -8077,6 +8079,11 @@ if (typeof jQuery === 'undefined') {
80778079
var isValid = false;
80788080
country = country.toUpperCase();
80798081
switch (country) {
8082+
// http://en.wikipedia.org/wiki/List_of_postal_codes_in_Austria
8083+
case 'AT':
8084+
isValid = /^([1-9]{1})(\d{3})$/.test(value);
8085+
break;
8086+
80808087
case 'BR':
80818088
isValid = /^(\d{2})([\.]?)(\d{3})([\-]?)(\d{3})$/.test(value);
80828089
break;
@@ -8085,19 +8092,24 @@ if (typeof jQuery === 'undefined') {
80858092
isValid = /^(?:A|B|C|E|G|H|J|K|L|M|N|P|R|S|T|V|X|Y){1}[0-9]{1}(?:A|B|C|E|G|H|J|K|L|M|N|P|R|S|T|V|W|X|Y|Z){1}\s?[0-9]{1}(?:A|B|C|E|G|H|J|K|L|M|N|P|R|S|T|V|W|X|Y|Z){1}[0-9]{1}$/i.test(value);
80868093
break;
80878094

8095+
case 'CH':
8096+
isValid = /^([1-9]{1})(\d{3})$/.test(value);
8097+
break;
8098+
80888099
case 'CZ':
80898100
// Test: http://regexr.com/39hhr
80908101
isValid = /^(\d{3})([ ]?)(\d{2})$/.test(value);
80918102
break;
80928103

8104+
// http://stackoverflow.com/questions/7926687/regular-expression-german-zip-codes
80938105
case 'DE':
8094-
isValid = /^([01245678][0-9]{4})$/.test(value);
8106+
isValid = /^(?!01000|99999)(0[1-9]\d{3}|[1-9]\d{4})$/.test(value);
80958107
break;
80968108

80978109
case 'DK':
80988110
isValid = /^(DK(-|\s)?)?\d{4}$/i.test(value);
80998111
break;
8100-
8112+
81018113
// http://en.wikipedia.org/wiki/Postal_codes_in_France
81028114
case 'FR':
81038115
isValid = /^[0-9]{5}$/i.test(value);
@@ -8106,7 +8118,7 @@ if (typeof jQuery === 'undefined') {
81068118
case 'GB':
81078119
isValid = this._gb(value);
81088120
break;
8109-
8121+
81108122
// http://www.eircode.ie/docs/default-source/Common/prepare-your-business-for-eircode---published-v2.pdf?sfvrsn=2
81118123
// Test: http://refiddle.com/1kpl
81128124
case 'IE':
@@ -8127,12 +8139,12 @@ if (typeof jQuery === 'undefined') {
81278139
case 'NL':
81288140
isValid = /^[1-9][0-9]{3} ?(?!sa|sd|ss)[a-z]{2}$/i.test(value);
81298141
break;
8130-
8142+
81318143
// Test: http://refiddle.com/1l2t
81328144
case 'PT':
81338145
isValid = /^[1-9]\d{3}-\d{3}$/.test(value);
81348146
break;
8135-
8147+
81368148
case 'RO':
81378149
isValid = /^(0[1-8]{1}|[1-9]{1}[0-5]{1})?[0-9]{4}$/i.test(value);
81388150
break;
@@ -8147,7 +8159,7 @@ if (typeof jQuery === 'undefined') {
81478159

81488160
case 'SG':
81498161
isValid = /^([0][1-9]|[1-6][0-9]|[7]([0-3]|[5-9])|[8][0-2])(\d{4})$/i.test(value);
8150-
break;
8162+
break;
81518163

81528164
case 'SK':
81538165
// Test: http://regexr.com/39hhr

dist/js/bootstrapValidator.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/language/de_DE.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,10 @@
344344
countryNotSupported: 'Der Ländercode %s wird nicht unterstützt',
345345
country: 'Bitte gültigen Postleitzahl für %s eingeben',
346346
countries: {
347+
AT: 'Österreich',
347348
BR: 'Brasilien',
348349
CA: 'Kanada',
350+
CH: 'Schweiz',
349351
CZ: 'Tschechische',
350352
DE: 'Deutschland',
351353
DK: 'Dänemark',

src/js/language/de_DE.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,10 @@
344344
countryNotSupported: 'Der Ländercode %s wird nicht unterstützt',
345345
country: 'Bitte gültigen Postleitzahl für %s eingeben',
346346
countries: {
347+
AT: 'Österreich',
347348
BR: 'Brasilien',
348349
CA: 'Kanada',
350+
CH: 'Schweiz',
349351
CZ: 'Tschechische',
350352
DE: 'Deutschland',
351353
DK: 'Dänemark',

src/js/validator/zipCode.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
countryNotSupported: 'The country code %s is not supported',
55
country: 'Please enter a valid postal code in %s',
66
countries: {
7+
AT: 'Austria',
78
BR: 'Brazil',
89
CA: 'Canada',
10+
CH: 'Switzerland',
911
CZ: 'Czech Republic',
1012
DE: 'Germany',
1113
DK: 'Denmark',
@@ -31,7 +33,7 @@
3133
country: 'country'
3234
},
3335

34-
COUNTRY_CODES: ['BR', 'CA', 'CZ', 'DE', 'DK', 'FR', 'GB', 'IE', 'IT', 'MA', 'NL', 'PT', 'RO', 'RU', 'SE', 'SG', 'SK', 'US'],
36+
COUNTRY_CODES: [ 'AT', 'BR', 'CA', 'CH', 'CZ', 'DE', 'DK', 'FR', 'GB', 'IE', 'IT', 'MA', 'NL', 'PT', 'RO', 'RU', 'SE', 'SG', 'SK', 'US'],
3537

3638
/**
3739
* Return true if and only if the input value is a valid country zip code
@@ -75,6 +77,11 @@
7577
var isValid = false;
7678
country = country.toUpperCase();
7779
switch (country) {
80+
// http://en.wikipedia.org/wiki/List_of_postal_codes_in_Austria
81+
case 'AT':
82+
isValid = /^([1-9]{1})(\d{3})$/.test(value);
83+
break;
84+
7885
case 'BR':
7986
isValid = /^(\d{2})([\.]?)(\d{3})([\-]?)(\d{3})$/.test(value);
8087
break;
@@ -83,19 +90,24 @@
8390
isValid = /^(?:A|B|C|E|G|H|J|K|L|M|N|P|R|S|T|V|X|Y){1}[0-9]{1}(?:A|B|C|E|G|H|J|K|L|M|N|P|R|S|T|V|W|X|Y|Z){1}\s?[0-9]{1}(?:A|B|C|E|G|H|J|K|L|M|N|P|R|S|T|V|W|X|Y|Z){1}[0-9]{1}$/i.test(value);
8491
break;
8592

93+
case 'CH':
94+
isValid = /^([1-9]{1})(\d{3})$/.test(value);
95+
break;
96+
8697
case 'CZ':
8798
// Test: http://regexr.com/39hhr
8899
isValid = /^(\d{3})([ ]?)(\d{2})$/.test(value);
89100
break;
90101

102+
// http://stackoverflow.com/questions/7926687/regular-expression-german-zip-codes
91103
case 'DE':
92-
isValid = /^([01245678][0-9]{4})$/.test(value);
104+
isValid = /^(?!01000|99999)(0[1-9]\d{3}|[1-9]\d{4})$/.test(value);
93105
break;
94106

95107
case 'DK':
96108
isValid = /^(DK(-|\s)?)?\d{4}$/i.test(value);
97109
break;
98-
110+
99111
// http://en.wikipedia.org/wiki/Postal_codes_in_France
100112
case 'FR':
101113
isValid = /^[0-9]{5}$/i.test(value);
@@ -104,7 +116,7 @@
104116
case 'GB':
105117
isValid = this._gb(value);
106118
break;
107-
119+
108120
// http://www.eircode.ie/docs/default-source/Common/prepare-your-business-for-eircode---published-v2.pdf?sfvrsn=2
109121
// Test: http://refiddle.com/1kpl
110122
case 'IE':
@@ -125,12 +137,12 @@
125137
case 'NL':
126138
isValid = /^[1-9][0-9]{3} ?(?!sa|sd|ss)[a-z]{2}$/i.test(value);
127139
break;
128-
140+
129141
// Test: http://refiddle.com/1l2t
130142
case 'PT':
131143
isValid = /^[1-9]\d{3}-\d{3}$/.test(value);
132144
break;
133-
145+
134146
case 'RO':
135147
isValid = /^(0[1-8]{1}|[1-9]{1}[0-5]{1})?[0-9]{4}$/i.test(value);
136148
break;
@@ -145,7 +157,7 @@
145157

146158
case 'SG':
147159
isValid = /^([0][1-9]|[1-6][0-9]|[7]([0-3]|[5-9])|[8][0-2])(\d{4})$/i.test(value);
148-
break;
160+
break;
149161

150162
case 'SK':
151163
// Test: http://regexr.com/39hhr

test/spec.js

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8236,7 +8236,7 @@ describe('zipCode', function() {
82368236
expect(this.bv.isValid()).toEqual(false);
82378237
}
82388238
});
8239-
8239+
82408240
it('Eircode (Ireland postal code)', function() {
82418241
this.bv.updateOption('zc', 'zipCode', 'country', 'IE');
82428242

@@ -8258,7 +8258,7 @@ describe('zipCode', function() {
82588258
expect(this.bv.isValid()).toEqual(false);
82598259
}
82608260
});
8261-
8261+
82628262
it('Portugal postal code', function() {
82638263
this.bv.updateOption('zc', 'zipCode', 'country', 'PT');
82648264

@@ -8280,4 +8280,70 @@ describe('zipCode', function() {
82808280
expect(this.bv.isValid()).toEqual(false);
82818281
}
82828282
});
8283+
8284+
it('Austria postal code', function() {
8285+
this.bv.updateOption('zc', 'zipCode', 'country', 'AT');
8286+
8287+
// Valid samples
8288+
var validSamples = ['6020', '1010', '4853'];
8289+
for (var i in validSamples) {
8290+
this.bv.resetForm();
8291+
this.$zipCode.val(validSamples[i]);
8292+
this.bv.validate();
8293+
expect(this.bv.isValid()).toBeTruthy();
8294+
}
8295+
8296+
// Invalid samples
8297+
var invalidSamples = ['0020', '12345', '102', '12AB', 'AT 6020 XY'];
8298+
for (i in invalidSamples) {
8299+
this.bv.resetForm();
8300+
this.$zipCode.val(invalidSamples[i]);
8301+
this.bv.validate();
8302+
expect(this.bv.isValid()).toEqual(false);
8303+
}
8304+
});
8305+
8306+
it('Germany postal code', function() {
8307+
this.bv.updateOption('zc', 'zipCode', 'country', 'DE');
8308+
8309+
// Valid samples
8310+
var validSamples = ['52238', '01001', '09107'];
8311+
for (var i in validSamples) {
8312+
this.bv.resetForm();
8313+
this.$zipCode.val(validSamples[i]);
8314+
this.bv.validate();
8315+
expect(this.bv.isValid()).toBeTruthy();
8316+
}
8317+
8318+
// Invalid samples
8319+
var invalidSamples = ['01000', '99999', '102', 'ABCDE', 'DE 52240 XY'];
8320+
for (i in invalidSamples) {
8321+
this.bv.resetForm();
8322+
this.$zipCode.val(invalidSamples[i]);
8323+
this.bv.validate();
8324+
expect(this.bv.isValid()).toEqual(false);
8325+
}
8326+
});
8327+
8328+
it('Switzerland postal code', function() {
8329+
this.bv.updateOption('zc', 'zipCode', 'country', 'CH');
8330+
8331+
// Valid samples
8332+
var validSamples = [ '8280', '8090', '8238', '9490'];
8333+
for (var i in validSamples) {
8334+
this.bv.resetForm();
8335+
this.$zipCode.val(validSamples[i]);
8336+
this.bv.validate();
8337+
expect(this.bv.isValid()).toBeTruthy();
8338+
}
8339+
8340+
// Invalid samples
8341+
var invalidSamples = ['0123', '99999', '102', 'ABCD', 'CH-5224 XY'];
8342+
for (i in invalidSamples) {
8343+
this.bv.resetForm();
8344+
this.$zipCode.val(invalidSamples[i]);
8345+
this.bv.validate();
8346+
expect(this.bv.isValid()).toEqual(false);
8347+
}
8348+
});
82838349
});

0 commit comments

Comments
 (0)