regexp.js 709 B

123456789101112131415161718192021
  1. (function($) {
  2. $.fn.bootstrapValidator.validators.regexp = {
  3. /**
  4. * Check if the element value matches given regular expression
  5. *
  6. * @param {BootstrapValidator} validator The validator plugin instance
  7. * @param {jQuery} $field Field element
  8. * @param {Object} options Consists of the following key:
  9. * - regexp: The regular expression you need to check
  10. * @returns {Boolean}
  11. */
  12. validate: function(validator, $field, options) {
  13. var value = $field.val();
  14. if (value == '') {
  15. return true;
  16. }
  17. return options.regexp.test(value);
  18. }
  19. };
  20. }(window.jQuery));