forked from stevenmills/bootstrapvalidator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbetween.js
27 lines (26 loc) · 1004 Bytes
/
between.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
(function($) {
$.fn.bootstrapValidator.validators.between = {
/**
* Return true if the input value is between (strictly or not) two given numbers
*
* @param {BootstrapValidator} validator The validator plugin instance
* @param {jQuery} $field Field element
* @param {Object} options Can consist of the following keys:
* - min
* - max
* - 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.min && value < options.max)
: (value >= options.min && value <= options.max);
}
};
}(window.jQuery));