forked from stevenmills/bootstrapvalidator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlessThan.js
23 lines (23 loc) · 920 Bytes
/
lessThan.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(function($) {
$.fn.bootstrapValidator.validators.lessThan = {
/**
* Return true if the input value is less than or equal to given number
*
* @param {BootstrapValidator} validator The validator plugin instance
* @param {jQuery} $field Field element
* @param {Object} options Can consist of the following keys:
* - value: The number used to compare to
* - inclusive [optional]: Can be true or false. Default is true
* - message: The invalid message
* @returns {Boolean}
*/
validate: function(validator, $field, options) {
var value = $field.val();
if (value == '') {
return true;
}
value = parseFloat(value);
return (options.inclusive === true) ? (value < options.value) : (value <= options.value);
}
};
}(window.jQuery));