diff --git a/reference/constraints.rst b/reference/constraints.rst index ac8ef5ae33c..25267ac0357 100644 --- a/reference/constraints.rst +++ b/reference/constraints.rst @@ -19,6 +19,7 @@ Validation Constraints Reference constraints/Regex constraints/Ip constraints/Uuid + constraints/PhoneNumber constraints/Range diff --git a/reference/constraints/PhoneNumber.rst b/reference/constraints/PhoneNumber.rst new file mode 100644 index 00000000000..3a4a9612ca9 --- /dev/null +++ b/reference/constraints/PhoneNumber.rst @@ -0,0 +1,107 @@ +Email +===== + +Validates that a value is a valid phone number. + ++----------------+---------------------------------------------------------------------------+ +| Applies to | :ref:`property or method ` | ++----------------+---------------------------------------------------------------------------+ +| Options | - `region`_ | ++----------------+---------------------------------------------------------------------------+ +| Class | :class:`Symfony\\Component\\Validator\\Constraints\\PhoneNumber` | ++----------------+---------------------------------------------------------------------------+ +| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\PhoneNumberValidator` | ++----------------+---------------------------------------------------------------------------+ + +Basic Usage +----------- + +.. configuration-block:: + + .. code-block:: yaml + + # src/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + phoneNumber: + - PhoneNumber: + message: This value is not a valid phone number. + region: FR + + .. code-block:: php-annotations + + // src/Acme/BlogBundle/Entity/Author.php + namespace Acme\BlogBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Author + { + /** + * @Assert\PhoneNumber( + * message = "This value is not a valid phone number.", + * region = FR + * ) + */ + protected $phoneNumber; + } + + .. code-block:: xml + + + + + + + + + + + + + + + + .. code-block:: php + + // src/Acme/BlogBundle/Entity/Author.php + namespace Acme\BlogBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Author + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('phoneNumber', new Assert\PhoneNumber(array( + 'message' => 'This value is not a valid phone number.', + 'region' => FR, + ))); + } + } + +Options +------- + +.. versionadded:: 2.6 + The PhoneNumber constraint was introduced in Symfony 2.6. + +region +~~~~~~ + +**type**: ``string`` **default**: ``null`` + +When null, it does not parse local phone number. If you entered a value (eg: 'FR'), +it will be able to parse and validate phone number. + +message +~~~~~~~ + +**type**: ``string`` **default**: ``This value is not a valid phone number.`` + +This message is shown if the underlying data is not a valid phone number. + +.. note:: PhoneNumber constraint rely on third-party library : https://github.com/giggsey/libphonenumber-for-php. It's require and you should install it via Composer. diff --git a/reference/constraints/map.rst.inc b/reference/constraints/map.rst.inc index 686ad22bca5..0cce2bf4fe8 100644 --- a/reference/constraints/map.rst.inc +++ b/reference/constraints/map.rst.inc @@ -21,6 +21,7 @@ String Constraints * :doc:`Regex ` * :doc:`Ip ` * :doc:`Uuid` +* :doc:`PhoneNumber ` Number Constraints ~~~~~~~~~~~~~~~~~~ diff --git a/reference/forms/types.rst b/reference/forms/types.rst index 82b22bde79c..bcf73d768ab 100644 --- a/reference/forms/types.rst +++ b/reference/forms/types.rst @@ -18,6 +18,7 @@ Form Types Reference types/percent types/search types/url + types/tel types/choice types/entity diff --git a/reference/forms/types/map.rst.inc b/reference/forms/types/map.rst.inc index b4362b3f318..df6679dfc24 100644 --- a/reference/forms/types/map.rst.inc +++ b/reference/forms/types/map.rst.inc @@ -11,6 +11,7 @@ Text Fields * :doc:`percent ` * :doc:`search ` * :doc:`url ` +* :doc:`tel ` Choice Fields ~~~~~~~~~~~~~ diff --git a/reference/forms/types/tel.rst b/reference/forms/types/tel.rst new file mode 100644 index 00000000000..f767cbe29bd --- /dev/null +++ b/reference/forms/types/tel.rst @@ -0,0 +1,60 @@ +.. index:: + single: Forms; Fields; tel + +Tel Field Type +=============== + +.. versionadded:: 2.6 + The Tel field type was introduced in Symfony 2.6. + +The tel field represents a text field for entering a telephone number. + ++-------------+--------------------------------------------------------------------+ +| Rendered as | ``input`` ``tel`` field | ++-------------+--------------------------------------------------------------------+ +| Inherited | - `empty_data`_ | +| options | - `required`_ | +| | - `label`_ | +| | - `label_attr`_ | +| | - `data`_ | +| | - `trim`_ | +| | - `read_only`_ | +| | - `disabled`_ | +| | - `error_bubbling`_ | +| | - `error_mapping`_ | +| | - `mapped`_ | ++-------------+--------------------------------------------------------------------+ +| Parent type | :doc:`form ` | ++-------------+--------------------------------------------------------------------+ +| Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\TelType` | ++-------------+--------------------------------------------------------------------+ + + +Inherited Options +----------------- + +These options inherit from the :doc:`form ` type: + +.. include:: /reference/forms/types/options/empty_data.rst.inc + +.. include:: /reference/forms/types/options/required.rst.inc + +.. include:: /reference/forms/types/options/label.rst.inc + +.. include:: /reference/forms/types/options/label_attr.rst.inc + +.. include:: /reference/forms/types/options/data.rst.inc + +.. include:: /reference/forms/types/options/trim.rst.inc + +.. include:: /reference/forms/types/options/read_only.rst.inc + +.. include:: /reference/forms/types/options/disabled.rst.inc + +.. include:: /reference/forms/types/options/error_bubbling.rst.inc + +.. include:: /reference/forms/types/options/error_mapping.rst.inc + +.. include:: /reference/forms/types/options/mapped.rst.inc + +.. note:: Tel field rely on third-party library : https://github.com/giggsey/libphonenumber-for-php. It's require and you should install it via Composer.