در این مورد چطور؟ Custom Validators :
class User extends CActiveRecord
{
public function rules()
{
return array(
array('postcode', 'pcValidator', 'allowEmpty' => true);
);
}
public function pcValidate($attribute, $params)
{
if($this->{$attribute} == '') {
if(!(isset($params['allowEmpty']) && $params['allowEmpty'])) {
$this->addError($attribute, $attribute . ' must be filled.');
}
}
elseif(strlen($postcode) != 10) {
$this->addError($attribute, $attribute . ' should be 10 digits only.');
}
elseif(preg_match('#[^13-9]#', $postcode)) {
$this->addError($attribute, $attribute . ' is not a valid post code.');
}
}
}