| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- (function($) {
- $.fn.bootstrapValidator.i18n.between = $.extend($.fn.bootstrapValidator.i18n.between || {}, {
- 'default': 'The value is not valid',
- inclusive: 'The value must be between %s and %s',
- notInclusive: 'The value must be between %s and %s strictly',
- getMessage: function(options) {
- return (options.inclusive === true || options.inclusive == undefined)
- ? $.fn.bootstrapValidator.helpers.format(this.inclusive, [options.min, options.max])
- : $.fn.bootstrapValidator.helpers.format(this.notInclusive, [options.min, options.max]);
- }
- });
- $.fn.bootstrapValidator.validators.between = {
- html5Attributes: {
- message: 'message',
- min: 'min',
- max: 'max',
- inclusive: 'inclusive'
- },
- enableByHtml5: function($field) {
- if ('range' == $field.attr('type')) {
- return {
- min: $field.attr('min'),
- max: $field.attr('max')
- };
- }
- return false;
- },
- /**
- * 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 || options.inclusive == undefined)
- ? (value >= options.min && value <= options.max)
- : (value > options.min && value < options.max);
- }
- };
- }(window.jQuery));
|