rules.js 729 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. export const simpleRequired = (message = '请输入') => {
  2. return {
  3. type: 'string',
  4. required: true,
  5. message,
  6. trigger: ['blur', 'change'],
  7. }
  8. }
  9. export const carNoRule = {
  10. min: 5,
  11. max: 8,
  12. message: '请输入正确的车牌号',
  13. }
  14. export const mobileRule = {
  15. pattern: /^1[3-9]\d{9}$/,
  16. transform(value) {
  17. return String(value);
  18. },
  19. message: '请输入正确的手机号',
  20. }
  21. export const idRule = {
  22. pattern: /^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}(\d|X|x)$/,
  23. transform(value) {
  24. return String(value);
  25. },
  26. message: '请输入正确的证件号',
  27. }
  28. export const mkRules = (fields, fun = simpleRequired) => {
  29. const ret = {}
  30. fields.forEach(d => {
  31. ret[d] = [fun()]
  32. })
  33. return ret
  34. }