Negative
验证值是否为负数。零既不是正数也不是负数,因此如果要允许零值,则必须使用 NegativeOrZero。
应用于 | 属性或方法 |
类 | Negative |
验证器 | LessThanValidator |
基本用法
以下约束确保银行账户 TransferItem
的 withdraw
值为负数(小于零)
1 2 3 4 5 6 7 8 9 10
// src/Entity/TransferItem.php
namespace App\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class TransferItem
{
#[Assert\Negative]
protected int $withdraw;
}
这项工作,包括代码示例,根据 Creative Commons BY-SA 3.0 许可获得许可。