我有一个带有验证规则的模型,例如:
[['x'], 'integer'],
[['x'], 'unique'],
现在如何添加如下规则:
x < 100
或类似
x >= 100
我有一个带有验证规则的模型,例如:
[['x'], 'integer'],
[['x'], 'unique'],
现在如何添加如下规则:
x < 100
或类似
x >= 100
它应该是:
['x', 'compare', 'compareValue' => 100, 'operator' => '<'],
和
['x', 'compare', 'compareValue' => 100, 'operator' => '>='],
因此。
阅读更多官方文档。
您还可以min
在数字或整数验证器上使用该属性:
['age', 'integer', 'min' => 0],
['amount', 'number', 'min' => 0],
还有一个max
选项。
Yii2 大于验证:
field_to 必须大于“field_from”。
字段 1:field_from
字段 2:field_to
[['field_to'], 'compare', 'when' => function($model) {
return $model->builtup_area != null;
}, 'whenClient' => "function (attribute, value){
return $('#form-field_from').val() != '';
}", 'compareAttribute' => 'field_from', 'operator' => '>', 'type' => 'number'],