Admin.php 1.2 KB

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