You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

56 lines
1.2 KiB

  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,12}|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. }