validate Multiple Select Box

hi,

Is there any way to make validation rule for multiple Select Box values. i want to allow user to select only four values out of all.

my code is as follow :

in view


echo $form->dropDownList($profile,'major',CHtml::listData(Subjects::model()->findAll(), 'name', 'name'),array('multiple'=>"multiple", 'size'=>"3", 'class'=>'multi'));

in controller i m saving it in comma separated string.


$profile->attributes=$_POST['Profile'];

$profile->major=implode(',',$profile->major);

which rule should I use to compare the total count of array elements return by the select box, and How ? :unsure:

I think this would require a custom validation rule, take a look at:

http://www.yiiframework.com/wiki/168/create-your-own-validation-rule

You might also need some javascript to help the user before submittion :)