4
4
.. versionadded :: 2.3
5
5
The Isbn constraint was introduced in Symfony 2.3.
6
6
7
+ .. caution ::
8
+
9
+ The ``isbn10 `` and ``isbn13 `` options are deprecated since Symfony 2.5
10
+ and will be removed in Symfony 3.0. Use the ``type `` option instead.
11
+ Furthermore, when using the ``type `` option, lowercase characters are no
12
+ longer supported starting in Symfony 2.5, as they are not allowed in ISBNs.
13
+
7
14
This constraint validates that an `International Standard Book Number (ISBN) `_
8
- is either a valid ISBN-10, a valid ISBN-13 or both .
15
+ is either a valid ISBN-10 or a valid ISBN-13.
9
16
10
17
+----------------+----------------------------------------------------------------------+
11
18
| Applies to | :ref: `property or method<validation-property-target> ` |
12
19
+----------------+----------------------------------------------------------------------+
13
- | Options | - `isbn10 `_ |
14
- | | - `isbn13 `_ |
20
+ | Options | - `type `_ |
21
+ | | - `message `_ |
15
22
| | - `isbn10Message `_ |
16
23
| | - `isbn13Message `_ |
17
24
| | - `bothIsbnMessage `_ |
@@ -25,7 +32,7 @@ Basic Usage
25
32
-----------
26
33
27
34
To use the ``Isbn `` validator, simply apply it to a property or method
28
- on an object that will contain a ISBN number .
35
+ on an object that will contain an ISBN.
29
36
30
37
.. configuration-block ::
31
38
@@ -36,9 +43,8 @@ on an object that will contain a ISBN number.
36
43
properties :
37
44
isbn :
38
45
- Isbn :
39
- isbn10 : true
40
- isbn13 : true
41
- bothIsbnMessage : This value is neither a valid ISBN-10 nor a valid ISBN-13.
46
+ type : isbn10
47
+ message : This value is not valid.
42
48
43
49
.. code-block :: php-annotations
44
50
@@ -49,9 +55,8 @@ on an object that will contain a ISBN number.
49
55
{
50
56
/**
51
57
* @Assert\Isbn(
52
- * isbn10 = true,
53
- * isbn13 = true,
54
- * bothIsbnMessage = "This value is neither a valid ISBN-10 nor a valid ISBN-13."
58
+ * type = isbn10,
59
+ * message: This value is not valid.
55
60
* )
56
61
*/
57
62
protected $isbn;
@@ -63,9 +68,8 @@ on an object that will contain a ISBN number.
63
68
<class name =" Acme\BookcaseBundle\Entity\Book" >
64
69
<property name =" isbn" >
65
70
<constraint name =" Isbn" >
66
- <option name =" isbn10" >true</option >
67
- <option name =" isbn13" >true</option >
68
- <option name =" bothIsbnMessage" >This value is neither a valid ISBN-10 nor a valid ISBN-13.</option >
71
+ <option name =" type" >isbn10</option >
72
+ <option name =" message" >This value is not valid.</option >
69
73
</constraint >
70
74
</property >
71
75
</class >
@@ -85,54 +89,53 @@ on an object that will contain a ISBN number.
85
89
public static function loadValidatorMetadata(ClassMetadata $metadata)
86
90
{
87
91
$metadata->addPropertyConstraint('isbn', new Assert\Isbn(array(
88
- 'isbn10' => true,
89
- 'isbn13' => true,
90
- 'bothIsbnMessage' => 'This value is neither a valid ISBN-10 nor a valid ISBN-13.'
92
+ 'type' => isbn10,
93
+ 'message' => 'This value is not valid.'
91
94
)));
92
95
}
93
96
}
94
97
95
98
Available Options
96
99
-----------------
97
100
98
- isbn10
99
- ~~~~~~
101
+ type
102
+ ~~~~
100
103
101
- **type **: ``boolean ``
104
+ **type **: ``string `` ** default **: `` null ``
102
105
103
- If this required option is set to `` true `` the constraint will check if the
104
- code is a valid ISBN-10 code .
106
+ The type of ISBN to validate against.
107
+ Valid values are `` isbn10 ``, `` isbn13 `` and `` null `` to accept any kind of ISBN .
105
108
106
- isbn13
107
- ~~~~~~
109
+ message
110
+ ~~~~~~~
108
111
109
- **type **: ``boolean ``
112
+ **type **: ``string `` ** default **: `` null ``
110
113
111
- If this required option is set to `` true `` the constraint will check if the
112
- code is a valid ISBN-13 code .
114
+ The message that will be shown if the value is not valid.
115
+ If not `` null ``, this message has priority over all the other messages .
113
116
114
117
isbn10Message
115
118
~~~~~~~~~~~~~
116
119
117
120
**type **: ``string `` **default **: ``This value is not a valid ISBN-10. ``
118
121
119
- The message that will be shown if the `isbn10 `_ option is true and the given
122
+ The message that will be shown if the `type `_ option is `` isbn10 `` and the given
120
123
value does not pass the ISBN-10 check.
121
124
122
125
isbn13Message
123
126
~~~~~~~~~~~~~
124
127
125
128
**type **: ``string `` **default **: ``This value is not a valid ISBN-13. ``
126
129
127
- The message that will be shown if the `isbn13 `_ option is true and the given
130
+ The message that will be shown if the `type `_ option is `` isbn13 `` and the given
128
131
value does not pass the ISBN-13 check.
129
132
130
133
bothIsbnMessage
131
134
~~~~~~~~~~~~~~~
132
135
133
136
**type **: ``string `` **default **: ``This value is neither a valid ISBN-10 nor a valid ISBN-13. ``
134
137
135
- The message that will be shown if both the `isbn10 `_ and ` isbn13 `_ options
136
- are true and the given value does not pass the ISBN-13 nor the ISBN-13 check .
138
+ The message that will be shown if the `type `_ option is `` null `` and the given
139
+ value does not pass any of the ISBN checks .
137
140
138
141
.. _`International Standard Book Number (ISBN)` : http://en.wikipedia.org/wiki/Isbn
0 commit comments