AdminValidate.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020-03-26
  7. *
  8. *
  9. */
  10. namespace app\validate\admin;
  11. use think\Validate;
  12. class AdminValidate extends Validate
  13. {
  14. protected $failException = true;
  15. protected $rule = [
  16. 'account|账号' => 'require|max:18|min:4',
  17. 'pwd|密码' => 'require|max:18|min:6',
  18. 'phone|联系电话' => 'isPhone',
  19. 'againPassword|确认密码' => 'require|max:18|min:6',
  20. 'real_name|管理员姓名' => 'max:16',
  21. 'roles|权限组' => 'require|array|min',
  22. 'status|启用状态' => 'require|in:0,1',
  23. ];
  24. protected function isPhone($val)
  25. {
  26. if ($val && !preg_match('/^1[3456789]{1}\d{9}$/', $val))
  27. return '请输入正确的手机号';
  28. else
  29. return true;
  30. }
  31. public function isUpdate()
  32. {
  33. unset($this->rule['pwd|密码'], $this->rule['againPassword|确认密码']);
  34. return $this;
  35. }
  36. public function isPassword()
  37. {
  38. unset($this->rule['account|账号'], $this->rule['real_name|姓名'], $this->rule['roles|权限组'], $this->rule['status|启用状态'], $this->rule['phone|联系电话']);
  39. return $this;
  40. }
  41. }