1

下面的模型扩展了 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')); ?>  

但是,上述验证不起作用。如何验证文本字段以仅允许整数。无论如何我可以进行验证

4

2 回答 2

3

try this

public function rules(){
return array(
    array('min_size, max_size', 'numerical', 'integerOnly'=>true));}
于 2013-11-20T10:43:43.997 回答
2

像在 v2 中一样使用

[['mobile'], 'integer'],
[['mobile'], 'string', 'min' => 10, 'max' => 10],
于 2015-02-13T09:50:02.800 回答