|
| 1 | +Issn |
| 2 | +==== |
| 3 | + |
| 4 | +.. versionadded:: 2.3 |
| 5 | + The ISSN validation is new in Symfony 2.3. |
| 6 | + |
| 7 | +Validates that a value is a valid `ISSN`_. |
| 8 | + |
| 9 | ++----------------+-----------------------------------------------------------------------+ |
| 10 | +| Applies to | :ref:`property or method<validation-property-target>` | |
| 11 | ++----------------+-----------------------------------------------------------------------+ |
| 12 | +| Options | - `message`_ | |
| 13 | +| | - `caseSensitive`_ | |
| 14 | +| | - `requireHyphen`_ | |
| 15 | ++----------------+-----------------------------------------------------------------------+ |
| 16 | +| Class | :class:`Symfony\\Component\\Validator\\Constraints\\Issn` | |
| 17 | ++----------------+-----------------------------------------------------------------------+ |
| 18 | +| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\IssnValidator` | |
| 19 | ++----------------+-----------------------------------------------------------------------+ |
| 20 | + |
| 21 | +Basic Usage |
| 22 | +----------- |
| 23 | + |
| 24 | +.. configuration-block:: |
| 25 | + |
| 26 | + .. code-block:: yaml |
| 27 | +
|
| 28 | + # src/JournalBundle/Resources/config/validation.yml |
| 29 | + Acme\JournalBundle\Entity\Journal: |
| 30 | + properties: |
| 31 | + issn: |
| 32 | + - Issn: ~ |
| 33 | +
|
| 34 | + .. code-block:: php-annotations |
| 35 | +
|
| 36 | + // src/Acme/JournalBundle/Entity/Journal.php |
| 37 | + namespace Acme\JournalBundle\Entity; |
| 38 | +
|
| 39 | + use Symfony\Component\Validator\Constraints as Assert; |
| 40 | +
|
| 41 | + class Journal |
| 42 | + { |
| 43 | + /** |
| 44 | + * @Assert\Issn |
| 45 | + */ |
| 46 | + protected $issn; |
| 47 | + } |
| 48 | +
|
| 49 | + .. code-block:: xml |
| 50 | +
|
| 51 | + <!-- src/Acme/JournalBundle/Resources/config/validation.xml --> |
| 52 | + <class name="Acme\JournalBundle\Entity\Journal"> |
| 53 | + <property name="issn"> |
| 54 | + <constraint name="Issn" /> |
| 55 | + </property> |
| 56 | + </class> |
| 57 | +
|
| 58 | + .. code-block:: php |
| 59 | +
|
| 60 | + // src/Acme/JournalBundle/Entity/Journal.php |
| 61 | + namespace Acme\JournalBundle\Entity; |
| 62 | +
|
| 63 | + use Symfony\Component\Validator\Mapping\ClassMetadata; |
| 64 | + use Symfony\Component\Validator\Constraints as Assert; |
| 65 | +
|
| 66 | + class Journal |
| 67 | + { |
| 68 | + public static function loadValidatorMetadata(ClassMetadata $metadata) |
| 69 | + { |
| 70 | + $metadata->addPropertyConstraint('issn', new Assert\Issn()); |
| 71 | + } |
| 72 | + } |
| 73 | +
|
| 74 | +Options |
| 75 | +------- |
| 76 | + |
| 77 | +message |
| 78 | +~~~~~~~ |
| 79 | + |
| 80 | +**type**: ``String`` default: ``This value is not a valid ISSN.`` |
| 81 | + |
| 82 | +The message shown if the given value is not a valid ISSN. |
| 83 | + |
| 84 | +caseSensitive |
| 85 | +~~~~~~~~~~~~~ |
| 86 | + |
| 87 | +**type**: ``Boolean`` default: ``false`` |
| 88 | + |
| 89 | +The validator will allow ISSN values to end with a lower case 'x' by default. |
| 90 | +When switching this to ``true``, the validator requires an upper case 'X'. |
| 91 | + |
| 92 | +requireHyphen |
| 93 | +~~~~~~~~~~~~~ |
| 94 | + |
| 95 | +**type**: ``Boolean`` default: ``false`` |
| 96 | + |
| 97 | +The validator will allow non hyphenated ISSN values by default. When switching |
| 98 | +this to ``true``, the validator requires an hyphenathed ISSN value. |
| 99 | + |
| 100 | +.. _`ISSN`: http://en.wikipedia.org/wiki/Issn |
| 101 | + |
0 commit comments