UserValidate.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\validate\admin;
  12. use think\Validate;
  13. class UserValidate extends Validate
  14. {
  15. protected $failException = true;
  16. protected $rule = [
  17. 'real_name|真实姓名' => 'max:25',
  18. 'phone|手机号' => 'isPhone',
  19. 'birthday|生日' => 'dateFormat:Y-m-d',
  20. 'card_id|身份证' => 'length:18',
  21. 'addres|用户地址' => 'max:64',
  22. 'mark|备注' => 'max:200',
  23. 'group_id|分组' => 'integer',
  24. 'label_id|标签' => 'array',
  25. 'is_promoter|推广人' => 'in:0,1',
  26. 'status|推广人' => 'in:0,1'
  27. ];
  28. protected function isPhone($val)
  29. {
  30. if (!preg_match('/^1[3456789]{1}\d{9}$/', $val))
  31. return '请输入正确的手机号';
  32. else
  33. return true;
  34. }
  35. protected function sceneCreate()
  36. {
  37. return $this->append('account','require|unique:user,account|max:16|min:5')
  38. ->append('pwd','require')
  39. ->append('repwd','require|confirm:pwd')
  40. ->append('sex','in:0,1,2');
  41. }
  42. protected $message = [
  43. 'account.require' => '账号必填',
  44. 'account.unique' => '账号已经存在',
  45. 'account.min' => '账号最小长度为5',
  46. 'account.max' => '账号最大长度为16',
  47. 'pwd.require' => '密码必填',
  48. 'repwd.require' => '确认密码必填',
  49. 'repwd.confirm' => '密码不一致',
  50. ];
  51. }