stringLength.js 911 B

12345678910111213141516171819202122232425262728
  1. (function($) {
  2. $.fn.bootstrapValidator.validators.stringLength = {
  3. /**
  4. * Check if the length of element value is less or more than given number
  5. *
  6. * @param {BootstrapValidator} validator The validator plugin instance
  7. * @param {jQuery} $field Field element
  8. * @param {Object} options Consists of following keys:
  9. * - min
  10. * - max
  11. * At least one of two keys is required
  12. * @returns {Boolean}
  13. */
  14. validate: function(validator, $field, options) {
  15. var value = $field.val();
  16. if (value == '') {
  17. return true;
  18. }
  19. var length = $.trim(value).length;
  20. if ((options.min && length < options.min) || (options.max && length > options.max)) {
  21. return false;
  22. }
  23. return true;
  24. }
  25. };
  26. }(window.jQuery));