Admin.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. 'mobile' => 'regex:1[3-9]\d{9}|unique:admin,mobile',
  15. ];
  16. /**
  17. * 提示消息
  18. */
  19. protected $message = [
  20. ];
  21. /**
  22. * 字段描述
  23. */
  24. protected $field = [
  25. ];
  26. /**
  27. * 验证场景
  28. */
  29. protected $scene = [
  30. 'add' => ['username', 'email', 'nickname', 'password', 'mobile'],
  31. 'edit' => ['username', 'email', 'nickname', 'password', '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. $this->message = array_merge($this->message, [
  43. 'username.regex' => __('Please input correct username'),
  44. 'password.regex' => __('Please input correct password')
  45. ]);
  46. parent::__construct($rules, $message, $field);
  47. }
  48. }