NotEqualTo

Validates that a value is not equal to another value, defined in the options. To force that a value is equal, see EqualTo.

値が、オプションで定義された別の値と等しくないことを検証します。値が等しいことを強制するには、EqualTo を参照してください。

Caution

注意

This constraint compares using !=, so 3 and "3" are considered equal. Use NotIdenticalTo to compare with !==.

この制約は != を使用して比較されるため、3 と "3" は等しいと見なされます。 NotIdenticalTo を使用して、!== と比較します。

Basic Usage

If you want to ensure that the firstName of a Person is not equal to Mary and that the age of a Person class is not 15, you could do the following:

Person の firstName が Mary と等しくなく、Person クラスの age が 15 でないことを確認するには、次のようにします。
  • Attributes
    属性
  • YAML
    YAML
  • XML
    XML
  • PHP
    PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// src/Entity/Person.php
namespace App\Entity;

use Symfony\Component\Validator\Constraints as Assert;

class Person
{
    #[Assert\NotEqualTo('Mary')]
    protected $firstName;

    #[Assert\NotEqualTo(
        value: 15,
    )]
    protected $age;
}

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 not be equal to {{ compared_value }}.

タイプ: 文字列 デフォルト: この値は {{ 比較値 }} と同じであってはなりません。

This is the message that will be shown if the value is equal.

これは、値が等しい場合に表示されるメッセージです。

You can use the following parameters in this message:

このメッセージでは、次のパラメーターを使用できます。
Parameter Description
{{ compared_value }} The expected value
{{ 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.

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

propertyPath

type: string

タイプ: 文字列

It defines the object property whose value is used to make the comparison.

比較に使用される値を持つオブジェクト プロパティを定義します。

For example, if you want to compare the $endDate property of some object with regard to the $startDate property of the same object, use propertyPath="startDate" in the comparison constraint of $endDate.

たとえば、あるオブジェクトの $endDate プロパティを同じオブジェクトの $startDate プロパティと比較する場合、$endDate の比較制約でpropertyPath="startDate" を使用します。

Tip

ヒント

When using this option, its value is available in error messages as the {{ compared_value_path }} placeholder. Although it's not intended to include it in the error messages displayed to end users, it's useful when using APIs for doing any mapping logic on client-side.

このオプションを使用する場合、その値はエラー メッセージで {{比較値パス}} プレースホルダーとして利用できます。エンド ユーザーに表示されるエラー メッセージに含めることは意図されていませんが、クライアント側でマッピング ロジックを実行するために API を使用する場合に役立ちます。

value

type: mixed [default option]

タイプ: 混合 [デフォルト オプション]

This option is required. It defines the comparison value. It can be a string, number or object.

このオプションは必須です。比較値を定義します。文字列、数値、またはオブジェクトにすることができます。