greaterThan.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. (function($) {
  2. $.fn.bootstrapValidator.validators.greaterThan = {
  3. html5Attributes: {
  4. message: 'message',
  5. value: 'value',
  6. inclusive: 'inclusive'
  7. },
  8. enableByHtml5: function($field) {
  9. var min = $field.attr('min');
  10. if (min) {
  11. return {
  12. value: min
  13. };
  14. }
  15. return false;
  16. },
  17. /**
  18. * Return true if the input value is greater than or equals to given number
  19. *
  20. * @param {BootstrapValidator} validator Validate plugin instance
  21. * @param {jQuery} $field Field element
  22. * @param {Object} options Can consist of the following keys:
  23. * - value: The number used to compare to
  24. * - inclusive [optional]: Can be true or false. Default is true
  25. * - message: The invalid message
  26. * @returns {Boolean}
  27. */
  28. validate: function(validator, $field, options) {
  29. var value = $field.val();
  30. if (value == '') {
  31. return true;
  32. }
  33. value = parseFloat(value);
  34. return (options.inclusive === true || options.inclusive==undefined) ? (value >= options.value) : (value > options.value);
  35. }
  36. }
  37. }(window.jQuery));