如何在Yii2中指定一个大于或小于特定数字或值的验证规则? [英] How to specify a validation rule in Yii2 which will be greater than or less than of a specific number or value?
本文介绍了如何在Yii2中指定一个大于或小于特定数字或值的验证规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有验证规则的模型,例如:
I have a model with a validation rule like:
[['x'], 'integer'],
[['x'], 'unique'],
现在如何添加如下规则:
Now how can I add a rule like:
x< 100
或类似
x> = 100
x < 100
or something like
x >= 100
推荐答案
应为:
['x', 'compare', 'compareValue' => 100, 'operator' => '<'],
和
['x', 'compare', 'compareValue' => 100, 'operator' => '>='],
相应地.
在官方文档中了解更多信息.
这篇关于如何在Yii2中指定一个大于或小于特定数字或值的验证规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文