I want to add a rule where user can post empty value, or integer value shoud be in range min-max. Is this possible without custom rules?
So, if min is 5 and max is 10, user could post values: empty, 5,6,7,8,9 or 10.
I want to add a rule where user can post empty value, or integer value shoud be in range min-max. Is this possible without custom rules?
So, if min is 5 and max is 10, user could post values: empty, 5,6,7,8,9 or 10.
您可以通过将其设置为、和来尝试使用数字验证器。min
5
max
10
allowEmpty
integerOnly
true
尝试这个 -
public function rules() {
return array(
array('test', 'safe'),
array('test', 'length', 'min' => 5, 'max'=>10,
'tooShort'=>Yii::t("translation", "{attribute} to short."),
'tooLong'=>Yii::t("translation", "{attribute} to long.")),
array('test', 'match', 'pattern'=>'/^[0-9]+$/'),
);
}