以下模型扩展了CFormModel,我需要提及它的规则,使得属性只允许整数。
class SearchForm extends CFormModel {
public $min_size;
public $max_size;
/**
* Declares the validation rules.
* The rules state that username and password are required,
* and password needs to be authenticated.
*/
public function rules() {
array('min_size, max_size', 'numerical', 'integerOnly'=>true),
);
}
使用 -
创建文本字段<?php echo $form->textField($model,'min_size', array('placeholder' => 'Min Sqft', 'style'=>'width:100px')); ?>
但是,上述验证无效。如何验证文本字段以仅允许整数。无论如何我可以做验证
答案 0 :(得分:3)
试试这个
public function rules(){
return array(
array('min_size, max_size', 'numerical', 'integerOnly'=>true));}
答案 1 :(得分:2)
像在v2中一样使用
[['mobile'], 'integer'],
[['mobile'], 'string', 'min' => 10, 'max' => 10],