123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace app\admin\validate;
- use think\Validate;
- class User extends Validate
- {
- /**
- * 验证规则
- */
- protected $rule = [
- // 'username' => 'require|regex:\w{3,30}|unique:user',
- 'nickname' => 'require|unique:user',
- 'password' => 'regex:\S{6,30}',
- // 'email' => 'require|email|unique:user',
- 'mobile' => 'unique:user',
- 'money' => 'checkmoeny:1'
- ];
- /**
- * 字段描述
- */
- protected $field = [
- ];
- /**
- * 提示消息
- */
- protected $message = [
- 'money.checkmoeny' => '请输入正确余额'
- ];
- /**
- * 验证场景
- */
- protected $scene = [
- 'add' => [],
- 'edit' => ['username', 'nickname', 'password', 'email', 'mobile', 'money'],
- ];
- protected function checkmoeny($money)
- {
- if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $money) || $money < 0) {
- return false;
- }
- return true;
- }
- public function __construct(array $rules = [], $message = [], $field = [])
- {
- $this->field = [
- 'username' => __('Username'),
- 'nickname' => __('Nickname'),
- 'password' => __('Password'),
- 'email' => __('Email'),
- 'mobile' => __('Mobile')
- ];
- parent::__construct($rules, $message, $field);
- }
- }
|