PositiveOrZero

Validates that a value is a positive number or equal to zero. If you don't want to allow zero as value, use Positive instead.

値が正の数またはゼロに等しいことを検証します。ゼロを値として許可したくない場合は、代わりに正を使用してください。

Basic Usage

The following constraint ensures that the number of siblings of a Person is positive or zero:

次の制約により、 Personis の兄弟の数が正またはゼロになります。
  • Attributes
    属性
  • YAML
    YAML
  • XML
    XML
  • PHP
    PHP
1
2
3
4
5
6
7
8
9
10
// src/Entity/Person.php
namespace App\Entity;

use Symfony\Component\Validator\Constraints as Assert;

class Person
{
    #[Assert\PositiveOrZero]
    protected $siblings;
}

Available Options

groups

type: array | string

タイプ: 配列 |ストリング

It defines the validation group or groups of this constraint. Read more about validation groups.

この制約の検証グループを定義します。検証グループの詳細を参照してください。

message

type: string default: This value should be either positive or zero.

タイプ: 文字列 デフォルト: この値は正またはゼロのいずれかです。

The default message supplied when the value is not greater than or equal to zero.

値がゼロ以下の場合に提供されるデフォルトのメッセージ。

You can use the following parameters in this message:

このメッセージでは、次のパラメーターを使用できます。
Parameter Description
{{ compared_value }} Always zero
{{ compared_value_type }} The expected value type
{{ value }} The current (invalid) value

payload

type: mixed default: null

タイプ: 混合 デフォルト: null

This option can be used to attach arbitrary domain-specific data to a constraint. The configured payload is not used by the Validator component, but its processing is completely up to you.

このオプションは、任意のドメイン固有のデータを制約に添付するために使用できます。構成されたペイロードは Validator コンポーネントによって使用されませんが、その処理は完全にユーザー次第です。

For example, you may want to use several error levels to present failed constraints differently in the front-end depending on the severity of the error.

たとえば、いくつかのエラー レベルを使用して、エラーの重大度に応じて、失敗した制約をフロントエンドで異なる方法で提示することができます。