AdminValidate.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\validate\admin;
  12. use think\Validate;
  13. class AdminValidate extends Validate
  14. {
  15. protected $failException = true;
  16. protected $rule = [
  17. 'account|账号' => 'require|max:18|min:4',
  18. 'pwd|密码' => 'require|max:18|min:6',
  19. 'phone|联系电话' => 'isPhone',
  20. 'againPassword|确认密码' => 'require|max:18|min:6',
  21. 'real_name|管理员姓名' => 'max:16',
  22. 'roles|权限组' => 'require|array|min',
  23. 'status|启用状态' => 'require|in:0,1',
  24. ];
  25. protected function isPhone($val)
  26. {
  27. if ($val && !preg_match('/^1[3456789]{1}\d{9}$/', $val))
  28. return '请输入正确的手机号';
  29. else
  30. return true;
  31. }
  32. public function isUpdate()
  33. {
  34. unset($this->rule['pwd|密码'], $this->rule['againPassword|确认密码']);
  35. return $this;
  36. }
  37. public function isPassword()
  38. {
  39. unset($this->rule['account|账号'], $this->rule['real_name|姓名'], $this->rule['roles|权限组'], $this->rule['status|启用状态'], $this->rule['phone|联系电话']);
  40. return $this;
  41. }
  42. }