Skip to content

Commit cb3489a

Browse files
committed
minor #15173 [Validator] Fix Regex htmlPattern examples (guilliamxavier)
This PR was merged into the 4.4 branch. Discussion ---------- [Validator] Fix Regex htmlPattern examples Cf. https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/Validator/Tests/Constraints/RegexTest.php Commits ------- 3f33c81 [Validator] Fix Regex htmlPattern examples
2 parents b01a241 + 3f33c81 commit cb3489a

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
@@ -175,12 +175,12 @@ Options
175175
This option specifies the pattern to use in the HTML5 ``pattern`` attribute.
176176
You usually don't need to specify this option because by default, the constraint
177177
will convert the pattern given in the `pattern`_ option into an HTML5 compatible
178-
pattern. This means that the delimiters are removed (e.g. ``/[a-z]+/`` becomes
179-
``[a-z]+``).
178+
pattern. Notably, the delimiters are removed and the anchors are implicit (e.g.
179+
``/^[a-z]+$/`` becomes ``[a-z]+``, and ``/[a-z]+/`` becomes ``.*[a-z]+.*``).
180180

181181
However, there are some other incompatibilities between both patterns which
182182
cannot be fixed by the constraint. For instance, the HTML5 ``pattern`` attribute
183-
does not support flags. If you have a pattern like ``/[a-z]+/i``, you
183+
does not support flags. If you have a pattern like ``/^[a-z]+$/i``, you
184184
need to specify the HTML5 compatible pattern in the ``htmlPattern`` option:
185185

186186
.. configuration-block::
@@ -197,7 +197,7 @@ need to specify the HTML5 compatible pattern in the ``htmlPattern`` option:
197197
/**
198198
* @Assert\Regex(
199199
* pattern = "/^[a-z]+$/i",
200-
* htmlPattern = "^[a-zA-Z]+$"
200+
* htmlPattern = "[a-zA-Z]+"
201201
* )
202202
*/
203203
protected $name;
@@ -211,7 +211,7 @@ need to specify the HTML5 compatible pattern in the ``htmlPattern`` option:
211211
name:
212212
- Regex:
213213
pattern: '/^[a-z]+$/i'
214-
htmlPattern: '^[a-zA-Z]+$'
214+
htmlPattern: '[a-zA-Z]+'
215215
216216
.. code-block:: xml
217217
@@ -225,7 +225,7 @@ need to specify the HTML5 compatible pattern in the ``htmlPattern`` option:
225225
<property name="name">
226226
<constraint name="Regex">
227227
<option name="pattern">/^[a-z]+$/i</option>
228-
<option name="htmlPattern">^[a-zA-Z]+$</option>
228+
<option name="htmlPattern">[a-zA-Z]+</option>
229229
</constraint>
230230
</property>
231231
</class>
@@ -245,7 +245,7 @@ need to specify the HTML5 compatible pattern in the ``htmlPattern`` option:
245245
{
246246
$metadata->addPropertyConstraint('name', new Assert\Regex([
247247
'pattern' => '/^[a-z]+$/i',
248-
'htmlPattern' => '^[a-zA-Z]+$',
248+
'htmlPattern' => '[a-zA-Z]+',
249249
]));
250250
}
251251
}

0 commit comments

Comments
 (0)