AdminValidate.php 1.1 KB

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