You can use my validator, it checks against number of values. I used exactly for the same purposes - to validate max and min number of selected values in multiselect:
<?php
class App_Validate_ValuesNumber extends Zend_Validate_Abstract
{
const TOO_LESS = 'tooLess';
const TOO_MUCH = 'tooMuch';
protected $_type = null;
protected $_val = null;
/**
* @var array
*/
protected $_messageTemplates = array(
self::TOO_LESS => "At least %num% values required",
self::TOO_MUCH => "Not more then %num% required",
);
/**
* @var array
*/
protected $_messageVariables = array(
'num' => '_val'
);
/**
* Constructor for the integer validator
*
* @param string $type Comparison type, that should be used
* TOO_LESS means that value should be greater then items number
* TOO_MUCH means opposite
* @param int $val Value to compare items number with
*/
public function __construct($type, $val)
{
$this->_type = $type;
$this->_val = $val;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is a valid integer
*
* @param string|integer $value
* @return boolean
*/
public function isValid($value)
{
// Value shoul dbe greated
if ($this->_type == self::TOO_LESS) {
if (count($value) < $this->_val) {
$this->_error(self::TOO_LESS);
return false;
}
}
// Value should be less
if ($this->_type == self::TOO_MUCH) {
if (count($value) > $this->_val) {
$this->_error(self::TOO_MUCH);
return false;
}
}
return true;
}
}