1

The below model extends CFormModel and I need to mention rules to it such that the attributes allow only integers.

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),

        );
    }

The textfield is created using -

<?php echo $form->textField($model,'min_size', array('placeholder' => 'Min Sqft', 'style'=>'width:100px')); ?>  

But, the above validation is not working. How can I validate the text field to allow integers only. Is there anyway I can do validation

user3004356
  • 870
  • 4
  • 16
  • 49

2 Answers2

3

try this

public function rules(){
return array(
    array('min_size, max_size', 'numerical', 'integerOnly'=>true));}
M Gaidhane
  • 531
  • 8
  • 29
2

use like in v2

[['mobile'], 'integer'],
[['mobile'], 'string', 'min' => 10, 'max' => 10],
Tri Q Tran
  • 5,500
  • 2
  • 37
  • 58
user2823361
  • 101
  • 5
  • Try to detail why this would work. Given as is it won't help anyone understand why/how your answer would solve OP problem. – Tensibai Feb 13 '15 at 12:48