ソースを参照

#96: Add base64 validator

nghuuphuoc 12 年 前
コミット
b5993e9d54

+ 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

ファイルの差分が大きいため隠しています
+ 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));