Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Validator] Document the "normalizer" option #9433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions reference/constraints/Email.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Options - `checkHost`_
- `groups`_
- `message`_
- `mode`_
- `normalizer`_
- `payload`_
Class :class:`Symfony\\Component\\Validator\\Constraints\\Email`
Validator :class:`Symfony\\Component\\Validator\\Constraints\\EmailValidator`
Expand Down Expand Up @@ -167,6 +168,7 @@ html5

This matches the pattern used for the `HTML5 email input element`_.

.. include:: /reference/constraints/_normalizer-option.rst.inc
.. include:: /reference/constraints/_payload-option.rst.inc

.. _egulias/email-validator: https://packagist.org/packages/egulias/email-validator
Expand Down
2 changes: 2 additions & 0 deletions reference/constraints/Ip.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ IPv6 and many other combinations.
Applies to :ref:`property or method <validation-property-target>`
Options - `groups`_
- `message`_
- `normalizer`_
- `payload`_
- `version`_
Class :class:`Symfony\\Component\\Validator\\Constraints\\Ip`
Expand Down Expand Up @@ -96,6 +97,7 @@ Parameter Description
``{{ value }}`` The current (invalid) value
=============== ==============================================================

.. include:: /reference/constraints/_normalizer-option.rst.inc
.. include:: /reference/constraints/_payload-option.rst.inc

version
Expand Down
2 changes: 2 additions & 0 deletions reference/constraints/Length.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Options - `charset`_
- `maxMessage`_
- `min`_
- `minMessage`_
- `normalizer`_
- `payload`_
Class :class:`Symfony\\Component\\Validator\\Constraints\\Length`
Validator :class:`Symfony\\Component\\Validator\\Constraints\\LengthValidator`
Expand Down Expand Up @@ -213,4 +214,5 @@ Parameter Description
``{{ value }}`` The current (invalid) value
================= ============================================================

.. include:: /reference/constraints/_normalizer-option.rst.inc
.. include:: /reference/constraints/_payload-option.rst.inc
12 changes: 12 additions & 0 deletions reference/constraints/NotBlank.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Applies to :ref:`property or method <validation-property-target>`
Options - `allowNull`_
- `groups`_
- `message`_
- `normalizer`_
- `payload`_
Class :class:`Symfony\\Component\\Validator\\Constraints\\NotBlank`
Validator :class:`Symfony\\Component\\Validator\\Constraints\\NotBlankValidator`
Expand Down Expand Up @@ -110,4 +111,15 @@ Parameter Description
``{{ value }}`` The current (invalid) value
=============== ==============================================================

normalizer
~~~~~~~~~~

**type**: ``string`` **default**: ``null``

If the given value is a ``string``, this option can be used to normalize it while
checking if it is valid. A ``callable`` must be passed.

For example, you may want to use :phpfunction:`trim` to ignore leading and
trailing whitespace during validation.

.. include:: /reference/constraints/_payload-option.rst.inc
2 changes: 2 additions & 0 deletions reference/constraints/Regex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Options - `groups`_
- `match`_
- `message`_
- `pattern`_
- `normalizer`_
- `payload`_
Class :class:`Symfony\\Component\\Validator\\Constraints\\Regex`
Validator :class:`Symfony\\Component\\Validator\\Constraints\\RegexValidator`
Expand Down Expand Up @@ -287,4 +288,5 @@ does *not* match this regular expression (via the :phpfunction:`preg_match`
PHP function). However, if `match`_ is set to false, then validation will
fail if the input string *does* match this pattern.

.. include:: /reference/constraints/_normalizer-option.rst.inc
.. include:: /reference/constraints/_payload-option.rst.inc
2 changes: 2 additions & 0 deletions reference/constraints/Url.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Options - `checkDNS`_
- `dnsMessage`_
- `groups`_
- `message`_
- `normalizer`_
- `payload`_
- `protocols`_
- `relativeProtocol`_
Expand Down Expand Up @@ -319,6 +320,7 @@ Parameter Description
}
}

.. include:: /reference/constraints/_normalizer-option.rst.inc
.. include:: /reference/constraints/_payload-option.rst.inc

protocols
Expand Down
2 changes: 2 additions & 0 deletions reference/constraints/Uuid.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ UUID versions can also be restricted using a whitelist.
Applies to :ref:`property or method <validation-property-target>`
Options - `groups`_
- `message`_
- `normalizer`_
- `payload`_
- `strict`_
- `versions`_
Expand Down Expand Up @@ -98,6 +99,7 @@ Parameter Description
``{{ value }}`` The current (invalid) value
=============== ==============================================================

.. include:: /reference/constraints/_normalizer-option.rst.inc
.. include:: /reference/constraints/_payload-option.rst.inc

strict
Expand Down
10 changes: 10 additions & 0 deletions reference/constraints/_normalizer-option.rst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
normalizer
~~~~~~~~~~

**type**: ``string`` **default**: ``null``

This option allows a ``callable`` to be passed in order to normalize the given
value while checking if it is valid.

For example, you may want to use :phpfunction:`trim` to ignore leading and
trailing whitespace during validation.