form.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. "use strict";
  2. const sheep_helper_test = require("../helper/test.js");
  3. const username = {
  4. rules: [
  5. {
  6. required: true,
  7. errorMessage: "请输入用户名"
  8. },
  9. {
  10. validateFunction: function(rule, value, data, callback) {
  11. if (!value) {
  12. callback("用户名不能为空");
  13. }
  14. return true;
  15. }
  16. }
  17. ]
  18. };
  19. const mobile = {
  20. rules: [
  21. {
  22. required: true,
  23. errorMessage: "请输入手机号"
  24. },
  25. {
  26. validateFunction: function(rule, value, data, callback) {
  27. if (!sheep_helper_test.test.mobile(value)) {
  28. callback("手机号码格式不正确");
  29. }
  30. return true;
  31. }
  32. }
  33. ]
  34. };
  35. const password = {
  36. rules: [
  37. {
  38. required: true,
  39. errorMessage: "请输入密码"
  40. },
  41. {
  42. validateFunction: function(rule, value, data, callback) {
  43. if (!/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]+\S{5,12}$/.test(value)) {
  44. callback("需包含字母和数字,长度在6-12之间");
  45. }
  46. return true;
  47. }
  48. }
  49. ]
  50. };
  51. const code = {
  52. rules: [
  53. {
  54. required: true,
  55. errorMessage: "请输入验证码"
  56. }
  57. ]
  58. };
  59. exports.code = code;
  60. exports.mobile = mobile;
  61. exports.password = password;
  62. exports.username = username;