whitespace.js 629 B

1234567891011121314151617181920
  1. import * as util from '../util';
  2. /**
  3. * Rule for validating whitespace.
  4. *
  5. * @param rule The validation rule.
  6. * @param value The value of the field on the source object.
  7. * @param source The source object being validated.
  8. * @param errors An array of errors that this rule may add
  9. * validation errors to.
  10. * @param options The validation options.
  11. * @param options.messages The validation messages.
  12. */
  13. function whitespace(rule, value, source, errors, options) {
  14. if (/^\s+$/.test(value) || value === '') {
  15. errors.push(util.format(options.messages.whitespace, rule.fullField));
  16. }
  17. }
  18. export default whitespace;