Member.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\common\validate;
  3. use think\Validate;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 验证器
  14. */
  15. class Member extends Validate
  16. {
  17. protected $rule = [
  18. 'member_name'=>'require|length:3,13',
  19. 'member_truename'=>'require|checkTruename',
  20. 'member_idcard'=>'require|checkIdcard',
  21. 'member_password'=>'require|length:6,20',
  22. 'member_email'=>'email',
  23. 'member_mobile'=>'length:11,11',
  24. 'member_nickname'=>'max:10',
  25. ];
  26. protected $message = [
  27. 'member_name.require'=>'用户名必填',
  28. 'member_name.length'=>'用户名长度在3到13位',
  29. 'member_truename.require'=>'真实姓名必填',
  30. 'member_truename.checkTruename'=>'真实姓名错误',
  31. 'member_idcard.require'=>'身份证必填',
  32. 'member_idcard.checkIdcard'=>'身份证错误',
  33. 'member_password.require'=>'密码为必填',
  34. 'member_password.length'=>'密码长度必须为6-20之间',
  35. 'member_email.email'=>'邮箱格式错误',
  36. 'member_mobile.length'=>'手机格式错误',
  37. 'member_nickname.max'=>'真实姓名长度超过10位',
  38. ];
  39. protected $scene = [
  40. 'add' => ['member_name', 'member_password', 'member_email'],
  41. 'edit' => ['member_email', 'member_mobile', 'member_email'],
  42. 'edit_information' => ['member_nickname'],
  43. 'login' => ['member_name', 'member_password'],
  44. 'register' => ['member_name', 'member_password'],
  45. 'auth' => ['member_truename', 'member_idcard'],
  46. ];
  47. protected function checkTruename($value,$rule,$data)
  48. {
  49. return preg_match('/^[\x{4e00}-\x{9fa5}]{2,4}$/u',$value)?true:false;
  50. }
  51. protected function checkIdcard($value,$rule,$data)
  52. {
  53. 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;
  54. }
  55. }