Skip to content

Commit 5e27db9

Browse files
committed
[#2864] Small tweaks thanks to @xabbuh on new Regex:htmlPattern option docs
1 parent bd0dc8b commit 5e27db9

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

reference/constraints/Regex.rst

+19-13
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,12 @@ htmlPattern
170170

171171
**type**: ``string|Boolean`` **default**: null
172172

173-
This option specifies the pattern to use in the html5 ``pattern`` attribute.
174-
By default, the constraint will convert the pattern given in the ``pattern``
175-
option into a html5 compatible pattern. This means that the delimeters are
176-
removed (e.g. ``/[a-z]+/`` becomes ``[a-z]+``).
173+
This option specifies the pattern to use in the HTML5 ``pattern`` attribute.
174+
You usually don't need to specify this option because by default, the constraint
175+
will convert the pattern given in the `pattern`_ option into an HTML5 compatible
176+
pattern. This means that the delimiters are removed (e.g. ``/[a-z]+/`` becomes ``[a-z]+``).
177177

178-
However, their are some other incompatibilities between both patterns which
178+
However, there are some other incompatibilities between both patterns which
179179
cannot be fixed by the constraint. For instance, the html5 pattern attribute
180180
does not support flags. If you have a pattern like ``/[a-z]+/i`` you need to
181181
specify the html5 compatible pattern in the ``htmlPattern`` option:
@@ -213,14 +213,20 @@ specify the html5 compatible pattern in the ``htmlPattern`` option:
213213
.. code-block:: xml
214214
215215
<!-- src/Acme/BlogBundle/Resources/config/validation.xml -->
216-
<class name="Acme\BlogBundle\Entity\Author">
217-
<property name="name">
218-
<constraint name="Regex">
219-
<option name="pattern">/^[a-z]+$/i</option>
220-
<option name="htmlPattern">^[a-zA-Z]+$</option>
221-
</constraint>
222-
</property>
223-
</class>
216+
<?xml version="1.0" encoding="UTF-8" ?>
217+
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
218+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
219+
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
220+
221+
<class name="Acme\BlogBundle\Entity\Author">
222+
<property name="name">
223+
<constraint name="Regex">
224+
<option name="pattern">/^[a-z]+$/i</option>
225+
<option name="htmlPattern">^[a-zA-Z]+$</option>
226+
</constraint>
227+
</property>
228+
</class>
229+
</constraint-mapping>
224230
225231
.. code-block:: php
226232

0 commit comments

Comments
 (0)