2

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.

4

2 回答 2

3

您可以通过将其设置为、和来尝试使用数字验证器。min5max10allowEmptyintegerOnlytrue

于 2013-04-12T16:31:57.740 回答
0

尝试这个 -

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]+$/'), 
        );
    }
于 2014-09-17T08:33:09.503 回答