ソースを参照

#135: Add integer validator

nghuuphuoc 12 年 前
コミット
d2c2329be9

+ 20 - 0
dist/js/bootstrapValidator.js

@@ -1234,6 +1234,26 @@
     };
 }(window.jQuery));
 ;(function($) {
+    $.fn.bootstrapValidator.validators.integer = {
+        /**
+         * Return true if the input value is an integer
+         *
+         * @param {BootstrapValidator} validator The validator plugin instance
+         * @param {jQuery} $field Field element
+         * @param {Object} options Can consist of the following key:
+         * - message: The invalid message
+         * @returns {Boolean}
+         */
+        validate: function(validator, $field, options) {
+            var value = $field.val();
+            if (value == '') {
+                return true;
+            }
+            return /^(?:-?(?:0|[1-9][0-9]*))$/.test(value);
+        }
+    };
+}(window.jQuery));
+;(function($) {
     $.fn.bootstrapValidator.validators.ip = {
         html5Attributes: ['message', 'ipv4', 'ipv6'],
 

ファイルの差分が大きいため隠しています
+ 1 - 1
dist/js/bootstrapValidator.min.js


+ 20 - 0
src/js/validator/integer.js

@@ -0,0 +1,20 @@
+(function($) {
+    $.fn.bootstrapValidator.validators.integer = {
+        /**
+         * Return true if the input value is an integer
+         *
+         * @param {BootstrapValidator} validator The validator plugin instance
+         * @param {jQuery} $field Field element
+         * @param {Object} options Can consist of the following key:
+         * - message: The invalid message
+         * @returns {Boolean}
+         */
+        validate: function(validator, $field, options) {
+            var value = $field.val();
+            if (value == '') {
+                return true;
+            }
+            return /^(?:-?(?:0|[1-9][0-9]*))$/.test(value);
+        }
+    };
+}(window.jQuery));