lessThan.js 920 B

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