User.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\admin\validate;
  3. use think\Validate;
  4. class User extends Validate
  5. {
  6. /**
  7. * 验证规则
  8. */
  9. protected $rule = [
  10. // 'username' => 'require|regex:\w{3,30}|unique:user',
  11. 'nickname' => 'require|unique:user',
  12. 'password' => 'regex:\S{6,30}',
  13. // 'email' => 'require|email|unique:user',
  14. 'mobile' => 'unique:user',
  15. 'money' => 'checkmoeny:1'
  16. ];
  17. /**
  18. * 字段描述
  19. */
  20. protected $field = [
  21. ];
  22. /**
  23. * 提示消息
  24. */
  25. protected $message = [
  26. 'money.checkmoeny' => '请输入正确余额'
  27. ];
  28. /**
  29. * 验证场景
  30. */
  31. protected $scene = [
  32. 'add' => [],
  33. 'edit' => ['username', 'nickname', 'password', 'email', 'mobile', 'money'],
  34. ];
  35. protected function checkmoeny($money)
  36. {
  37. if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $money) || $money < 0) {
  38. return false;
  39. }
  40. return true;
  41. }
  42. public function __construct(array $rules = [], $message = [], $field = [])
  43. {
  44. $this->field = [
  45. 'username' => __('Username'),
  46. 'nickname' => __('Nickname'),
  47. 'password' => __('Password'),
  48. 'email' => __('Email'),
  49. 'mobile' => __('Mobile')
  50. ];
  51. parent::__construct($rules, $message, $field);
  52. }
  53. }