Browse Source

Add Danish zip code validation

Emil Rømer Christensen 11 years ago
parent
commit
00394e0d12

+ 17 - 2
demo/validators.html

@@ -90,9 +90,17 @@
                             <div class="form-group">
                                 <label class="col-lg-3 control-label">US zip code</label>
                                 <div class="col-lg-3">
-                                    <input type="text" class="form-control" name="zipCode" />
+                                    <input type="text" class="form-control" name="usZipCode" />
                                 </div>
                             </div>
+
+                            <div class="form-group">
+                                <label class="col-lg-3 control-label">DK zip code</label>
+                                <div class="col-lg-3">
+                                    <input type="text" class="form-control" name="dkZipCode" />
+                                </div>
+                            </div>
+
                         </fieldset>
 
                         <fieldset>
@@ -203,13 +211,20 @@ $(document).ready(function() {
                     }
                 }
             },
-            zipCode: {
+            usZipCode: {
                 validators: {
                     usZipCode: {
                         message: 'The input is not a valid US zip code'
                     }
                 }
             },
+            dkZipCode: {
+                validators: {
+                    dkZipCode: {
+                        message: 'The input is not a valid DK zip code'
+                    }
+                }
+            },
             password: {
                 validators: {
                     notEmpty: {

+ 19 - 0
dist/js/bootstrapValidator.js

@@ -539,6 +539,25 @@
     }
 }(window.jQuery));
 ;(function($) {
+    $.fn.bootstrapValidator.validators.dkZipCode = {
+        /**
+         * Return true if and only if the input value is a valid DK zip code
+         *
+         * @param {BootstrapValidator} validator The validator plugin instance
+         * @param {jQuery} $field Field element
+         * @param {Object} options
+         * @returns {Boolean}
+         */
+        validate: function(validateInstance, $field, options) {
+            var value = $field.val();
+            if (value == '') {
+                return true;
+            }
+            return /^(DK(-|\s)?)?\d{4}$/i.test(value);
+        }
+    };
+}(window.jQuery));
+;(function($) {
     $.fn.bootstrapValidator.validators.emailAddress = {
         /**
          * Return true if and only if the input value is a valid email address

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


+ 19 - 0
src/js/validator/dkZipCode.js

@@ -0,0 +1,19 @@
+(function($) {
+    $.fn.bootstrapValidator.validators.dkZipCode = {
+        /**
+         * Return true if and only if the input value is a valid DK zip code
+         *
+         * @param {BootstrapValidator} validator The validator plugin instance
+         * @param {jQuery} $field Field element
+         * @param {Object} options
+         * @returns {Boolean}
+         */
+        validate: function(validateInstance, $field, options) {
+            var value = $field.val();
+            if (value == '') {
+                return true;
+            }
+            return /^(DK(-|\s)?)?\d{4}$/i.test(value);
+        }
+    };
+}(window.jQuery));