Browse Source

#242: Add separator option to the numeric validator

nghuuphuoc 11 years ago
parent
commit
58e86791f7

+ 1 - 0
CHANGELOG.md

@@ -5,6 +5,7 @@
 * Add ```$.fn.bootstrapValidator.helpers.date``` for validating a date, re-used in ```date```, ```id```, [```vat```](http://bootstrapvalidator.com/validators/vat/) validators
 * [#233](https://github.com/nghuuphuoc/bootstrapvalidator/issues/233): Add ```threshold``` option
 * [#232](https://github.com/nghuuphuoc/bootstrapvalidator/issues/232): Add ```id``` validator
+* [#242](https://github.com/nghuuphuoc/bootstrapvalidator/issues/242): Add ```separator``` option to the [```numeric``` validator](http://bootstrapvalidator.com/validators/numeric/)
 * When parsing options from HTML attributes, don't add the field which hasn't validators. It improves fixes for [#191](https://github.com/nghuuphuoc/bootstrapvalidator/issues/191), [#223](https://github.com/nghuuphuoc/bootstrapvalidator/issues/223)
 
 ## v0.4.4 (2014-05-05)

+ 1 - 1
dist/css/bootstrapValidator.min.css

@@ -3,7 +3,7 @@
  *
  * A jQuery plugin to validate form fields. Use with Bootstrap 3
  *
- * @version     v0.5.0-dev
+ * @version     v0.4.5-dev
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT

+ 11 - 1
dist/js/bootstrapValidator.js

@@ -3,7 +3,7 @@
  *
  * A jQuery plugin to validate form fields. Use with Bootstrap 3
  *
- * @version     v0.5.0-dev
+ * @version     v0.4.5-dev
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT
@@ -2606,6 +2606,11 @@
 }(window.jQuery));
 ;(function($) {
     $.fn.bootstrapValidator.validators.numeric = {
+        html5Attributes: {
+            message: 'message',
+            separator: 'separator'
+        },
+
         /**
          * Validate decimal number
          *
@@ -2613,6 +2618,7 @@
          * @param {jQuery} $field Field element
          * @param {Object} options Consist of key:
          * - message: The invalid message
+         * - separator: The decimal separator. Can be "." (default), ","
          * @returns {Boolean}
          */
         validate: function(validator, $field, options) {
@@ -2620,6 +2626,10 @@
             if (value == '') {
                 return true;
             }
+            var separator = options.separator || '.';
+            if (separator != '.') {
+                value = value.replace(separator, '.');
+            }
 
             return !isNaN(parseFloat(value)) && isFinite(value);
         }

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


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

@@ -1,5 +1,10 @@
 (function($) {
     $.fn.bootstrapValidator.validators.numeric = {
+        html5Attributes: {
+            message: 'message',
+            separator: 'separator'
+        },
+
         /**
          * Validate decimal number
          *
@@ -7,6 +12,7 @@
          * @param {jQuery} $field Field element
          * @param {Object} options Consist of key:
          * - message: The invalid message
+         * - separator: The decimal separator. Can be "." (default), ","
          * @returns {Boolean}
          */
         validate: function(validator, $field, options) {
@@ -14,6 +20,10 @@
             if (value == '') {
                 return true;
             }
+            var separator = options.separator || '.';
+            if (separator != '.') {
+                value = value.replace(separator, '.');
+            }
 
             return !isNaN(parseFloat(value)) && isFinite(value);
         }