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.
You can try to use numerical validator by setting its min to 5, max to 10, allowEmpty and integerOnly to true.
Try this -
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]+$/'),
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With