Skip to content

Commit f5e459e

Browse files
committed
Merge branch '4.4' into 5.2
* 4.4: [Validator] Fix Regex htmlPattern examples
2 parents 0ab866b + cb3489a commit f5e459e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

reference/constraints/Regex.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ Options
205205
This option specifies the pattern to use in the HTML5 ``pattern`` attribute.
206206
You usually don't need to specify this option because by default, the constraint
207207
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]+.*``).
210210

211211
However, there are some other incompatibilities between both patterns which
212212
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
214214
need to specify the HTML5 compatible pattern in the ``htmlPattern`` option:
215215

216216
.. configuration-block::
@@ -227,7 +227,7 @@ need to specify the HTML5 compatible pattern in the ``htmlPattern`` option:
227227
/**
228228
* @Assert\Regex(
229229
* pattern = "/^[a-z]+$/i",
230-
* htmlPattern = "^[a-zA-Z]+$"
230+
* htmlPattern = "[a-zA-Z]+"
231231
* )
232232
*/
233233
protected $name;
@@ -257,7 +257,7 @@ need to specify the HTML5 compatible pattern in the ``htmlPattern`` option:
257257
name:
258258
- Regex:
259259
pattern: '/^[a-z]+$/i'
260-
htmlPattern: '^[a-zA-Z]+$'
260+
htmlPattern: '[a-zA-Z]+'
261261
262262
.. code-block:: xml
263263
@@ -271,7 +271,7 @@ need to specify the HTML5 compatible pattern in the ``htmlPattern`` option:
271271
<property name="name">
272272
<constraint name="Regex">
273273
<option name="pattern">/^[a-z]+$/i</option>
274-
<option name="htmlPattern">^[a-zA-Z]+$</option>
274+
<option name="htmlPattern">[a-zA-Z]+</option>
275275
</constraint>
276276
</property>
277277
</class>
@@ -291,7 +291,7 @@ need to specify the HTML5 compatible pattern in the ``htmlPattern`` option:
291291
{
292292
$metadata->addPropertyConstraint('name', new Assert\Regex([
293293
'pattern' => '/^[a-z]+$/i',
294-
'htmlPattern' => '^[a-zA-Z]+$',
294+
'htmlPattern' => '[a-zA-Z]+',
295295
]));
296296
}
297297
}

0 commit comments

Comments
 (0)