Browse Source

zipCode validator adds support for Italian, Dutch postcodes

nghuuphuoc 11 years ago
parent
commit
be9f0a76de
4 changed files with 34 additions and 25 deletions
  1. 1 0
      CHANGELOG.md
  2. 16 12
      dist/js/bootstrapValidator.js
  3. 1 1
      dist/js/bootstrapValidator.min.js
  4. 16 12
      src/js/validator/zipCode.js

+ 1 - 0
CHANGELOG.md

@@ -6,6 +6,7 @@
 * [#233](https://github.com/nghuuphuoc/bootstrapvalidator/issues/233): Add ```threshold``` option
 * [#232](https://github.com/nghuuphuoc/bootstrapvalidator/issues/232): Add ```id``` validator
 * [#242](https://github.com/nghuuphuoc/bootstrapvalidator/issues/242): Add ```separator``` option to the [```numeric``` validator](http://bootstrapvalidator.com/validators/numeric/)
+* [```zipCode``` validator](http://bootstrapvalidator.com/validators/zipCode/) adds support for Italian, Dutch postcodes
 * Change default ```submitButtons``` to ```[type="submit"]``` to support ```input type="submit"```
 * [#238](https://github.com/nghuuphuoc/bootstrapvalidator/issues/238): The submit buttons are not sent
 * Fix the issue that the hidden fields generated by other plugins might not be validated

+ 16 - 12
dist/js/bootstrapValidator.js

@@ -4330,6 +4330,8 @@
          * - CA (Canada)
          * - DK (Denmark)
          * - GB (United Kingdom)
+         * - IT (Italy)
+         * - NL (Netherlands)
          * - SE (Sweden)
          * @returns {Boolean}
          */
@@ -4341,17 +4343,19 @@
 
             var country = (options.country || 'US').toUpperCase();
             switch (country) {
-                case 'CA':
-                    return /(?:A|B|C|E|G|J|K|L|M|N|P|R|S|T|V|X|Y){1}[0-9]{1}(?:A|B|C|E|G|J|K|L|M|N|P|R|S|T|V|X|Y){1}\s?[0-9]{1}(?:A|B|C|E|G|J|K|L|M|N|P|R|S|T|V|X|Y){1}[0-9]{1}/i.test(value);
-                case 'DK':
-                    return /^(DK(-|\s)?)?\d{4}$/i.test(value);
-                case 'GB':
-                    return this._gb(value);
-                case 'SE':
-                    return /^(S-)?\d{3}\s?\d{2}$/i.test(value);
+                case 'CA': return /(?:A|B|C|E|G|J|K|L|M|N|P|R|S|T|V|X|Y){1}[0-9]{1}(?:A|B|C|E|G|J|K|L|M|N|P|R|S|T|V|X|Y){1}\s?[0-9]{1}(?:A|B|C|E|G|J|K|L|M|N|P|R|S|T|V|X|Y){1}[0-9]{1}/i.test(value);
+                case 'DK': return /^(DK(-|\s)?)?\d{4}$/i.test(value);
+                case 'GB': return this._gb(value);
+
+                // http://en.wikipedia.org/wiki/List_of_postal_codes_in_Italy
+                case 'IT': return /^(I-|IT-)?\d{5}$/i.test(value);
+
+                // http://en.wikipedia.org/wiki/Postal_codes_in_the_Netherlands
+                case 'NL': return /^[1-9][0-9]{3} ?(?!sa|sd|ss)[a-z]{2}$/i.test(value);
+
+                case 'SE': return /^(S-)?\d{3}\s?\d{2}$/i.test(value);
                 case 'US':
-                default:
-                    return /^\d{4,5}([\-]\d{4})?$/.test(value);
+                default: return /^\d{4,5}([\-]\d{4})?$/.test(value);
             }
         },
 
@@ -4370,7 +4374,7 @@
             var firstChar  = '[ABCDEFGHIJKLMNOPRSTUWYZ]',     // Does not accept QVX
                 secondChar = '[ABCDEFGHKLMNOPQRSTUVWXY]',     // Does not accept IJZ
                 thirdChar  = '[ABCDEFGHJKPMNRSTUVWXY]',
-                fouthChar  = '[ABEHMNPRVWXY]',
+                fourthChar = '[ABEHMNPRVWXY]',
                 fifthChar  = '[ABDEFGHJLNPQRSTUWXYZ]',
                 regexps = [
                     // AN NAA, ANN NAA, AAN NAA, AANN NAA format
@@ -4378,7 +4382,7 @@
                     // ANA NAA
                     new RegExp('^(' + firstChar + '{1}[0-9]{1}' + thirdChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
                     // AANA NAA
-                    new RegExp('^(' + firstChar + '{1}' + secondChar + '{1}?[0-9]{1}' + fouthChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
+                    new RegExp('^(' + firstChar + '{1}' + secondChar + '{1}?[0-9]{1}' + fourthChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
 
                     new RegExp('^(BF1)(\\s*)([0-6]{1}[ABDEFGHJLNPQRST]{1}[ABDEFGHJLNPQRSTUWZYZ]{1})$', 'i'),        // BFPO postcodes
                     /^(GIR)(\s*)(0AA)$/i,                       // Special postcode GIR 0AA

File diff suppressed because it is too large
+ 1 - 1
dist/js/bootstrapValidator.min.js


+ 16 - 12
src/js/validator/zipCode.js

@@ -19,6 +19,8 @@
          * - CA (Canada)
          * - DK (Denmark)
          * - GB (United Kingdom)
+         * - IT (Italy)
+         * - NL (Netherlands)
          * - SE (Sweden)
          * @returns {Boolean}
          */
@@ -30,17 +32,19 @@
 
             var country = (options.country || 'US').toUpperCase();
             switch (country) {
-                case 'CA':
-                    return /(?:A|B|C|E|G|J|K|L|M|N|P|R|S|T|V|X|Y){1}[0-9]{1}(?:A|B|C|E|G|J|K|L|M|N|P|R|S|T|V|X|Y){1}\s?[0-9]{1}(?:A|B|C|E|G|J|K|L|M|N|P|R|S|T|V|X|Y){1}[0-9]{1}/i.test(value);
-                case 'DK':
-                    return /^(DK(-|\s)?)?\d{4}$/i.test(value);
-                case 'GB':
-                    return this._gb(value);
-                case 'SE':
-                    return /^(S-)?\d{3}\s?\d{2}$/i.test(value);
+                case 'CA': return /(?:A|B|C|E|G|J|K|L|M|N|P|R|S|T|V|X|Y){1}[0-9]{1}(?:A|B|C|E|G|J|K|L|M|N|P|R|S|T|V|X|Y){1}\s?[0-9]{1}(?:A|B|C|E|G|J|K|L|M|N|P|R|S|T|V|X|Y){1}[0-9]{1}/i.test(value);
+                case 'DK': return /^(DK(-|\s)?)?\d{4}$/i.test(value);
+                case 'GB': return this._gb(value);
+
+                // http://en.wikipedia.org/wiki/List_of_postal_codes_in_Italy
+                case 'IT': return /^(I-|IT-)?\d{5}$/i.test(value);
+
+                // http://en.wikipedia.org/wiki/Postal_codes_in_the_Netherlands
+                case 'NL': return /^[1-9][0-9]{3} ?(?!sa|sd|ss)[a-z]{2}$/i.test(value);
+
+                case 'SE': return /^(S-)?\d{3}\s?\d{2}$/i.test(value);
                 case 'US':
-                default:
-                    return /^\d{4,5}([\-]\d{4})?$/.test(value);
+                default: return /^\d{4,5}([\-]\d{4})?$/.test(value);
             }
         },
 
@@ -59,7 +63,7 @@
             var firstChar  = '[ABCDEFGHIJKLMNOPRSTUWYZ]',     // Does not accept QVX
                 secondChar = '[ABCDEFGHKLMNOPQRSTUVWXY]',     // Does not accept IJZ
                 thirdChar  = '[ABCDEFGHJKPMNRSTUVWXY]',
-                fouthChar  = '[ABEHMNPRVWXY]',
+                fourthChar = '[ABEHMNPRVWXY]',
                 fifthChar  = '[ABDEFGHJLNPQRSTUWXYZ]',
                 regexps = [
                     // AN NAA, ANN NAA, AAN NAA, AANN NAA format
@@ -67,7 +71,7 @@
                     // ANA NAA
                     new RegExp('^(' + firstChar + '{1}[0-9]{1}' + thirdChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
                     // AANA NAA
-                    new RegExp('^(' + firstChar + '{1}' + secondChar + '{1}?[0-9]{1}' + fouthChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
+                    new RegExp('^(' + firstChar + '{1}' + secondChar + '{1}?[0-9]{1}' + fourthChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
 
                     new RegExp('^(BF1)(\\s*)([0-6]{1}[ABDEFGHJLNPQRST]{1}[ABDEFGHJLNPQRSTUWZYZ]{1})$', 'i'),        // BFPO postcodes
                     /^(GIR)(\s*)(0AA)$/i,                       // Special postcode GIR 0AA