Admin.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\company\validate;
  3. use think\Validate;
  4. class Admin extends Validate
  5. {
  6. /**
  7. * 验证规则
  8. */
  9. protected $rule = [
  10. 'mobile' => 'require|regex:1\d{10}|unique:PcAdmin,mobile',
  11. 'username' => 'require|regex:1\d{10}|unique:PcAdmin,username',
  12. 'nickname' => 'require',
  13. 'password' => 'require|regex:\S{32}',
  14. // 'email' => 'require|email|unique:PcAdmin,email',
  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. }