Browse Source

Merge pull request #447 from AlaskanShade/master

Zip code and isExcluded updates
Phuoc Nguyen 11 years ago
parent
commit
e3f73c0a64
2 changed files with 10 additions and 7 deletions
  1. 3 3
      src/js/bootstrapValidator.js
  2. 7 4
      src/js/validator/zipCode.js

+ 3 - 3
src/js/bootstrapValidator.js

@@ -88,9 +88,9 @@
                 .find('[name], [data-bv-field]')
                     .each(function() {
                         var $field = $(this);
-                        if (that._isExcluded($field)) {
-                            return;
-                        }
+                        //if (that._isExcluded($field)) {
+                        //    return;
+                        //}
 
                         var field = $field.attr('name') || $field.attr('data-bv-field'),
                             opts  = that._parseOptions($field);

+ 7 - 4
src/js/validator/zipCode.js

@@ -31,7 +31,8 @@
     $.fn.bootstrapValidator.validators.zipCode = {
         html5Attributes: {
             message: 'message',
-            country: 'country'
+            country: 'country',
+            countryfield: 'countryfield'
         },
 
         COUNTRIES: ['CA', 'DK', 'GB', 'IT', 'NL', 'SE', 'SG', 'US'],
@@ -44,6 +45,7 @@
          * @param {Object} options Consist of key:
          * - message: The invalid message
          * - country: The ISO 3166 country code
+         * - counryfield: Another field that contains the country code
          *
          * Currently it supports the following countries:
          * - US (United State)
@@ -58,11 +60,12 @@
          */
         validate: function(validator, $field, options) {
             var value = $field.val();
-            if (value === '' || !options.country) {
+            if (value === '' || (!options.country && !options.countryfield)) {
                 return true;
             }
 
-            var country = (options.country || 'US').toUpperCase();
+            var cField = options.countryfield ? validator.getFieldElements(options.countryfield) : null;
+            var country = (cField ? cField.val() : null || options.country || 'US').toUpperCase();
             if ($.inArray(country, this.COUNTRIES) === -1) {
                 return false;
             }
@@ -82,7 +85,7 @@
                 case 'SG': return /^([0][1-9]|[1-6][0-9]|[7]([0-3]|[5-9])|[8][0-2])(\d{4})$/i.test(value);
                 case 'US':
                 /* falls through */
-                default: return /^\d{4,5}([\-]\d{4})?$/.test(value);
+                default: return /^\d{4,5}([\-]?\d{4})?$/.test(value);
             }
         },