|
| 1 | +Isbn |
| 2 | +==== |
| 3 | + |
| 4 | +This constraint permits that a ISBN (International Standard Book Numbers) |
| 5 | +number is either a valid ISBN-10, a valid ISBN-13 code or both on a value. |
| 6 | + |
| 7 | ++----------------+----------------------------------------------------------------------+ |
| 8 | +| Applies to | :ref:`property or method<validation-property-target>` | |
| 9 | ++----------------+----------------------------------------------------------------------+ |
| 10 | +| Options | - `isbn10Message`_ | |
| 11 | +| | - `isbn13Message`_ | |
| 12 | +| | - `bothIsbnMessage`_ | |
| 13 | +| | - `isbn10`_ | |
| 14 | +| | - `isbn13`_ | |
| 15 | ++----------------+----------------------------------------------------------------------+ |
| 16 | +| Class | :class:`Symfony\\Component\\Validator\\Constraints\\Isbn` | |
| 17 | ++----------------+----------------------------------------------------------------------+ |
| 18 | +| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\IsbnValidator` | |
| 19 | ++----------------+----------------------------------------------------------------------+ |
| 20 | + |
| 21 | +Basic Usage |
| 22 | +----------- |
| 23 | + |
| 24 | +To use the ``Isbn`` validator, simply apply it to a property or method |
| 25 | +on an object that will contain a ISBN number. |
| 26 | + |
| 27 | +.. configuration-block:: |
| 28 | + |
| 29 | + .. code-block:: yaml |
| 30 | +
|
| 31 | + # src/Acme/DemoBundle/Resources/config/validation.yml |
| 32 | + Acme\DemoBundle\Entity\AcmeEntity: |
| 33 | + properties: |
| 34 | + isbn: |
| 35 | + - Isbn: |
| 36 | + isbn10: true |
| 37 | + isbn13: true |
| 38 | + bothIsbnMessage: This value is neither a valid ISBN-10 nor a valid ISBN-13. |
| 39 | +
|
| 40 | + .. code-block:: xml |
| 41 | +
|
| 42 | + <!-- src/Acme/DemoBundle/Resources/config/validation.xml --> |
| 43 | + <class name="Acme\DemoBundle\Entity\AcmeEntity"> |
| 44 | + <property name="isbn"> |
| 45 | + <constraint name="Isbn"> |
| 46 | + <option name="isbn10">true</option> |
| 47 | + <option name="isbn13">true</option> |
| 48 | + <option name="bothIsbnMessage">This value is neither a valid ISBN-10 nor a valid ISBN-13.</option> |
| 49 | + </constraint> |
| 50 | + </property> |
| 51 | + </class> |
| 52 | +
|
| 53 | + .. code-block:: php-annotations |
| 54 | +
|
| 55 | + // src/Acme/DemoBundle/Entity/AcmeEntity.php |
| 56 | + use Symfony\Component\Validator\Constraints as Assert; |
| 57 | +
|
| 58 | + class AcmeEntity |
| 59 | + { |
| 60 | + /** |
| 61 | + * @Assert\Isbn( |
| 62 | + * isbn10 = true, |
| 63 | + * isbn13 = true, |
| 64 | + * bothIsbnMessage = "This value is neither a valid ISBN-10 nor a valid ISBN-13." |
| 65 | + * ) |
| 66 | + */ |
| 67 | + protected $isbn; |
| 68 | + } |
| 69 | +
|
| 70 | + .. code-block:: php |
| 71 | +
|
| 72 | + // src/Acme/DemoBundle/Entity/AcmeEntity.php |
| 73 | + use Symfony\Component\Validator\Mapping\ClassMetadata; |
| 74 | + use Symfony\Component\Validator\Constraints\Isbn; |
| 75 | +
|
| 76 | + class AcmeEntity |
| 77 | + { |
| 78 | + protected $isbn; |
| 79 | +
|
| 80 | + public static function loadValidatorMetadata(ClassMetadata $metadata) |
| 81 | + { |
| 82 | + $metadata->addPropertyConstraint('isbn', new Isbn(array( |
| 83 | + 'isbn10' => true, |
| 84 | + 'isbn13' => true, |
| 85 | + 'bothIsbnMessage' => 'This value is neither a valid ISBN-10 nor a valid ISBN-13.' |
| 86 | + ))); |
| 87 | + } |
| 88 | + } |
| 89 | +
|
| 90 | +Available Options |
| 91 | +----------------- |
| 92 | + |
| 93 | +isbn10Message |
| 94 | +~~~~~~~~~~~~~ |
| 95 | + |
| 96 | +**type**: ``string`` **default**: ``This value is not a valid ISBN-10.`` |
| 97 | + |
| 98 | +The message that will be shown if the option isbn10 is true |
| 99 | +and the given value does not pass the ISBN-10 check. |
| 100 | + |
| 101 | +isbn13Message |
| 102 | +~~~~~~~~~~~~~ |
| 103 | + |
| 104 | +**type**: ``string`` **default**: ``This value is not a valid ISBN-13.`` |
| 105 | + |
| 106 | +The message that will be shown if the option isbn13 is true |
| 107 | +and the given value does not pass the ISBN-13 check. |
| 108 | + |
| 109 | +bothIsbnMessage |
| 110 | +~~~~~~~~~~~~~~~ |
| 111 | + |
| 112 | +**type**: ``string`` **default**: ``This value is neither a valid ISBN-10 nor a valid ISBN-13.`` |
| 113 | + |
| 114 | +The message that will be shown if the options (isbn10, isbn13) is true |
| 115 | +and the given value does not pass the ISBN-13 nor ISBN-13 check. |
| 116 | + |
| 117 | +isbn10 |
| 118 | +~~~~~~ |
| 119 | + |
| 120 | +**type**: ``boolean`` [:ref:`default option<validation-default-option>`] |
| 121 | + |
| 122 | +If this required option is set to ``true`` the constraint will check |
| 123 | +if the code is a valid ISBN-10 code. |
| 124 | + |
| 125 | +isbn13 |
| 126 | +~~~~~~ |
| 127 | + |
| 128 | +**type**: ``boolean`` [:ref:`default option<validation-default-option>`] |
| 129 | + |
| 130 | +If this required option is set to ``true`` the constraint will check |
| 131 | +if the code is a valid ISBN-13 code. |
0 commit comments