form.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /**
  2. * Validate v1.0.0 通用验证
  3. * @description 项目中用到的表单验证规则
  4. */
  5. import test from '@/sheep/helper/test.js';
  6. // 手机号
  7. export const mobile = {
  8. rules: [
  9. {
  10. required: true,
  11. errorMessage: '请输入手机号',
  12. },
  13. {
  14. validateFunction: function (rule, value, data, callback) {
  15. if (!test.mobile(value)) {
  16. callback('手机号码格式不正确');
  17. }
  18. return true;
  19. },
  20. },
  21. ],
  22. };
  23. // 密码
  24. export const password = {
  25. rules: [
  26. {
  27. required: true,
  28. errorMessage: '请输入密码',
  29. },
  30. {
  31. validateFunction: function (rule, value, data, callback) {
  32. if (!/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]+\S{5,12}$/.test(value)) {
  33. callback('需包含字母和数字,长度在6-12之间');
  34. }
  35. return true;
  36. },
  37. },
  38. ],
  39. };
  40. // 短信验证码
  41. export const code = {
  42. rules: [
  43. {
  44. required: true,
  45. errorMessage: '请输入验证码',
  46. },
  47. ],
  48. };
  49. // 真实姓名
  50. export const realName = {
  51. rules: [
  52. {
  53. required: true,
  54. errorMessage: '请输入姓名',
  55. },
  56. {
  57. validateFunction: function (rule, value, data, callback) {
  58. if (!test.chinese(value)) {
  59. callback('请输入汉字');
  60. }
  61. return true;
  62. },
  63. },
  64. ],
  65. };
  66. export const taxName = {
  67. rules: [
  68. {
  69. required: true,
  70. errorMessage: '请输入发票抬头名称',
  71. },
  72. {
  73. validateFunction: function (rule, value, data, callback) {
  74. if (!test.chinese(value)) {
  75. callback('请输入汉字');
  76. }
  77. return true;
  78. },
  79. },
  80. ],
  81. };
  82. // 税号
  83. export const taxNo = {
  84. rules: [
  85. {
  86. required: true,
  87. errorMessage: '请输入税号',
  88. },
  89. ],
  90. };
  91. // 开户行
  92. export const bankName = {
  93. rules: [
  94. {
  95. required: true,
  96. errorMessage: '请输入开户行',
  97. },
  98. {
  99. validateFunction: function (rule, value, data, callback) {
  100. if (!test.chinese(value)) {
  101. callback('请输入汉字');
  102. }
  103. return true;
  104. },
  105. },
  106. ],
  107. };
  108. // 银行卡号
  109. export const bankCode = {
  110. rules: [
  111. {
  112. required: true,
  113. errorMessage: '请输入银行卡号',
  114. },
  115. {
  116. validateFunction: function (rule, value, data, callback) {
  117. if (!test.number(value)) {
  118. callback('请输入正确账号');
  119. }
  120. return true;
  121. },
  122. },
  123. ],
  124. };
  125. // 支付宝账号
  126. export const alipayAccount = {
  127. rules: [
  128. {
  129. required: true,
  130. errorMessage: '请输入支付宝账号',
  131. },
  132. {
  133. validateFunction: function (rule, value, data, callback) {
  134. let isEmail = test.email(value);
  135. let isMobile = test.mobile(value);
  136. if (!isEmail && !isMobile) {
  137. callback('请输入正确账号');
  138. }
  139. return true;
  140. },
  141. },
  142. ],
  143. };
  144. export default {
  145. mobile,
  146. alipayAccount,
  147. bankCode,
  148. bankName,
  149. realName,
  150. password,
  151. code,
  152. taxNo,
  153. taxName,
  154. };