Browse Source

#96: Add base64 validator

nghuuphuoc 12 years ago
parent
commit
b5993e9d54
3 changed files with 43 additions and 1 deletions
  1. 21 0
      dist/js/bootstrapValidator.js
  2. 1 1
      dist/js/bootstrapValidator.min.js
  3. 21 0
      src/js/validator/base64.js

+ 21 - 0
dist/js/bootstrapValidator.js

@@ -543,6 +543,27 @@
     $.fn.bootstrapValidator.Constructor = BootstrapValidator;
 }(window.jQuery));
 ;(function($) {
+    $.fn.bootstrapValidator.validators.base64 = {
+        /**
+         * Return true if the input value is a base 64 encoded string.
+         *
+         * @param {BootstrapValidator} validator The validator plugin instance
+         * @param {jQuery} $field Field element
+         * @param {Object} options Can consist of the following keys:
+         * - message: The invalid message
+         * @returns {Boolean}
+         */
+        validate: function(validator, $field, options) {
+            var value = $field.val();
+            if (value == '') {
+                return true;
+            }
+
+            return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.test(value);
+        }
+    };
+}(window.jQuery));
+;(function($) {
     $.fn.bootstrapValidator.validators.between = {
         /**
          * Return true if the input value is between (strictly or not) two given numbers

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


+ 21 - 0
src/js/validator/base64.js

@@ -0,0 +1,21 @@
+(function($) {
+    $.fn.bootstrapValidator.validators.base64 = {
+        /**
+         * Return true if the input value is a base 64 encoded string.
+         *
+         * @param {BootstrapValidator} validator The validator plugin instance
+         * @param {jQuery} $field Field element
+         * @param {Object} options Can consist of the following keys:
+         * - message: The invalid message
+         * @returns {Boolean}
+         */
+        validate: function(validator, $field, options) {
+            var value = $field.val();
+            if (value == '') {
+                return true;
+            }
+
+            return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.test(value);
+        }
+    };
+}(window.jQuery));