pattern.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _rule = require('../rule/');
  6. var _rule2 = _interopRequireDefault(_rule);
  7. var _util = require('../util');
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  9. /**
  10. * Validates a regular expression pattern.
  11. *
  12. * Performs validation when a rule only contains
  13. * a pattern property but is not declared as a string type.
  14. *
  15. * @param rule The validation rule.
  16. * @param value The value of the field on the source object.
  17. * @param callback The callback function.
  18. * @param source The source object being validated.
  19. * @param options The validation options.
  20. * @param options.messages The validation messages.
  21. */
  22. function pattern(rule, value, callback, source, options) {
  23. var errors = [];
  24. var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
  25. if (validate) {
  26. if ((0, _util.isEmptyValue)(value, 'string') && !rule.required) {
  27. return callback();
  28. }
  29. _rule2['default'].required(rule, value, source, errors, options);
  30. if (!(0, _util.isEmptyValue)(value, 'string')) {
  31. _rule2['default'].pattern(rule, value, source, errors, options);
  32. }
  33. }
  34. callback(errors);
  35. }
  36. exports['default'] = pattern;
  37. module.exports = exports['default'];