Cform Rules Validation Fails

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



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

It looks like a line is missing in your [font="Courier New"]rules()[/font] method:

public function rules() {

  return array(

    array('min_size, max_size', 'numerical', 'integerOnly'=>true),



If that doesn’t help: Can you possibly c&p your controller code?

try this


 array('percent', 'numerical', 'allowEmpty' => true,

                                'integerOnly' => false, 'min' => 0, 'max' => 100),