Browse Source

#128: Add numeric validator

nghuuphuoc 12 years ago
parent
commit
91411fcd13
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/numeric.js

+ 21 - 0
dist/js/bootstrapValidator.js

@@ -1713,6 +1713,27 @@
     };
 }(window.jQuery));
 ;(function($) {
+    $.fn.bootstrapValidator.validators.numeric = {
+        /**
+         * Validate decimal number
+         *
+         * @param {BootstrapValidator} validator The validator plugin instance
+         * @param {jQuery} $field Field element
+         * @param {Object} options Consist of key:
+         * - message: The invalid message
+         * @returns {Boolean}
+         */
+        validate: function(validator, $field, options) {
+            var value = $field.val();
+            if (value == '') {
+                return true;
+            }
+
+            return !isNaN(parseFloat(value)) && isFinite(value);
+        }
+    };
+}(window.jQuery));
+;(function($) {
     $.fn.bootstrapValidator.validators.phone = {
         html5Attributes: {
             message: 'message',

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


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

@@ -0,0 +1,21 @@
+(function($) {
+    $.fn.bootstrapValidator.validators.numeric = {
+        /**
+         * Validate decimal number
+         *
+         * @param {BootstrapValidator} validator The validator plugin instance
+         * @param {jQuery} $field Field element
+         * @param {Object} options Consist of key:
+         * - message: The invalid message
+         * @returns {Boolean}
+         */
+        validate: function(validator, $field, options) {
+            var value = $field.val();
+            if (value == '') {
+                return true;
+            }
+
+            return !isNaN(parseFloat(value)) && isFinite(value);
+        }
+    };
+}(window.jQuery));