User.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace app\admin\validate;
  3. use think\Validate;
  4. class User extends Validate
  5. {
  6. /**
  7. * 验证规则
  8. */
  9. protected $rule = [
  10. 'username' => 'require|regex:\w{3,32}|unique:user',
  11. 'nickname' => 'require|unique:user',
  12. 'password' => 'regex:\S{6,32}',
  13. 'email' => 'require|email',
  14. 'mobile' => 'require'
  15. ];
  16. /**
  17. * 字段描述
  18. */
  19. protected $field = [
  20. ];
  21. /**
  22. * 提示消息
  23. */
  24. protected $message = [
  25. ];
  26. /**
  27. * 验证场景
  28. */
  29. protected $scene = [
  30. 'add' => [],
  31. 'edit' => ['username', 'nickname', 'password', 'email', 'mobile'],
  32. ];
  33. public function __construct(array $rules = [], $message = [], $field = [])
  34. {
  35. $this->field = [
  36. 'username' => __('Username'),
  37. 'nickname' => __('Nickname'),
  38. 'password' => __('Password'),
  39. 'email' => __('Email'),
  40. 'mobile' => __('Mobile')
  41. ];
  42. parent::__construct($rules, $message, $field);
  43. }
  44. }