如何验证数组中的模型字段

I have the three text field that have the same id.The user must not fill the three text box.They may be fill one or two . now how can i validate the text box using yii model rules.

<?php echo $form->textArea($model,'taskname[]',array('class'=>'bg-focus form-control','value'=>$edit_info['varProjectname'])); ?>

So what is your table? you can achiev this in controller, where you can check how many fields are filled. For example use if statement to check, and if there arne not filled two fields use

Yii::app()->user->setFlash();
Yii::app()->end();

about Yii::app()->user->setFlash() you can read here http://www.yiiframework.com/wiki/21/how-to-work-with-flash-messages/

I do not fully understand when you say "same id" and then your question says "model fields in array". Assuming you are talking about three fields in the 'same model' you could use custom validation as below:

Use custom validation method: e.g. [Note: this will add error to all the three fields]

In your rules:

    ...
    array('fieldOne, fieldTwo, fieldThree', 'validateThreeFields'),
    ...


public function validateThreeFields($attribute, $params) {

  // check if all fields empty
  if ((empty($this->fieldOne) && empty($this->fieldTwo) && empty($this->fieldThree))

        // or if none are empty
        || (!empty($this->fieldOne) && !empty($this->fieldTwo) && !empty($this->fieldThree))) {

    $this->addError($attribute, 'Your error message');

  }
}