Member.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\common\validate;
  3. use think\Validate;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 验证器
  10. */
  11. class Member extends Validate
  12. {
  13. protected $rule = [
  14. 'member_name' => 'require|length:3,13',
  15. 'member_truename' => 'require|checkTruename',
  16. 'member_idcard' => 'require|checkIdcard',
  17. 'member_password' => 'require|length:6,20',
  18. 'member_email' => 'email',
  19. 'member_mobile' => 'length:11,11',
  20. 'member_nickname' => 'max:10',
  21. ];
  22. protected $message = [
  23. 'member_name.require' => '用户名必填',
  24. 'member_name.length' => '用户名长度在3到13位',
  25. 'member_truename.require' => '真实姓名必填',
  26. 'member_truename.checkTruename' => '真实姓名错误',
  27. 'member_idcard.require' => '身份证必填',
  28. 'member_idcard.checkIdcard' => '身份证错误',
  29. 'member_password.require' => '密码为必填',
  30. 'member_password.length' => '密码长度必须为6-20之间',
  31. 'member_email.email' => '邮箱格式错误',
  32. 'member_mobile.length' => '手机格式错误',
  33. 'member_nickname.max' => '真实姓名长度超过10位',
  34. ];
  35. protected $scene = [
  36. 'add' => ['member_name', 'member_password', 'member_email'],
  37. 'edit' => ['member_email', 'member_mobile', 'member_email'],
  38. 'edit_information' => ['member_nickname'],
  39. 'login' => ['member_name', 'member_password'],
  40. 'register' => ['member_name', 'member_password'],
  41. 'auth' => ['member_truename', 'member_idcard'],
  42. ];
  43. protected function checkTruename($value, $rule, $data)
  44. {
  45. return preg_match('/^[\x{4e00}-\x{9fa5}]{2,4}$/u', $value) ? true : false;
  46. }
  47. protected function checkIdcard($value, $rule, $data)
  48. {
  49. return preg_match('/^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/', $value) ? true : false;
  50. }
  51. }