在rules里面自定义规则,代码如下:
public function rules()
{
return [
['username','required','message'=>'请输入用户名'],
['username' , 'checkname' , 'skipOnEmpty' => false],
];
}
public function checkname($attribute , $params)
{
if(!preg_match("/^[\w]{6,20}$/" , $this->$attribute)){
$this->addError($attribute , '用户名必须为6~20的数字或字母');
}
}在rules里面自定义规则,代码如下:
public function rules()
{
return [
['username','required','message'=>'请输入用户名'],
['username' , 'checkname' , 'skipOnEmpty' => false],
];
}
public function checkname($attribute , $params)
{
if(!preg_match("/^[\w]{6,20}$/" , $this->$attribute)){
$this->addError($attribute , '用户名必须为6~20的数字或字母');
}
}
rules方法你在哪里调用的无效?看你贴的code里面也没有调用rules地方啊!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号