@@ -205,12 +205,12 @@ Options
205
205
This option specifies the pattern to use in the HTML5 ``pattern `` attribute.
206
206
You usually don't need to specify this option because by default, the constraint
207
207
will convert the pattern given in the `pattern `_ option into an HTML5 compatible
208
- pattern. This means that the delimiters are removed (e.g. `` /[a-z]+/ `` becomes
209
- ``[a-z]+ ``).
208
+ pattern. Notably, the delimiters are removed and the anchors are implicit (e.g.
209
+ ``/^ [a-z]+$/ `` becomes `` [a-z]+ ``, and `` /[a-z]+/ `` becomes `` .*[a-z]+.* ``).
210
210
211
211
However, there are some other incompatibilities between both patterns which
212
212
cannot be fixed by the constraint. For instance, the HTML5 ``pattern `` attribute
213
- does not support flags. If you have a pattern like ``/[a-z]+/i ``, you
213
+ does not support flags. If you have a pattern like ``/^ [a-z]+$ /i ``, you
214
214
need to specify the HTML5 compatible pattern in the ``htmlPattern `` option:
215
215
216
216
.. configuration-block ::
@@ -227,7 +227,7 @@ need to specify the HTML5 compatible pattern in the ``htmlPattern`` option:
227
227
/**
228
228
* @Assert\Regex(
229
229
* pattern = "/^[a-z]+$/i",
230
- * htmlPattern = "^ [a-zA-Z]+$ "
230
+ * htmlPattern = "[a-zA-Z]+"
231
231
* )
232
232
*/
233
233
protected $name;
@@ -257,7 +257,7 @@ need to specify the HTML5 compatible pattern in the ``htmlPattern`` option:
257
257
name :
258
258
- Regex :
259
259
pattern : ' /^[a-z]+$/i'
260
- htmlPattern : ' ^ [a-zA-Z]+$ '
260
+ htmlPattern : ' [a-zA-Z]+'
261
261
262
262
.. code-block :: xml
263
263
@@ -271,7 +271,7 @@ need to specify the HTML5 compatible pattern in the ``htmlPattern`` option:
271
271
<property name =" name" >
272
272
<constraint name =" Regex" >
273
273
<option name =" pattern" >/^[a-z]+$/i</option >
274
- <option name =" htmlPattern" >^ [a-zA-Z]+$ </option >
274
+ <option name =" htmlPattern" >[a-zA-Z]+</option >
275
275
</constraint >
276
276
</property >
277
277
</class >
@@ -291,7 +291,7 @@ need to specify the HTML5 compatible pattern in the ``htmlPattern`` option:
291
291
{
292
292
$metadata->addPropertyConstraint('name', new Assert\Regex([
293
293
'pattern' => '/^[a-z]+$/i',
294
- 'htmlPattern' => '^ [a-zA-Z]+$ ',
294
+ 'htmlPattern' => '[a-zA-Z]+',
295
295
]));
296
296
}
297
297
}
0 commit comments