@@ -175,12 +175,12 @@ Options
175
175
This option specifies the pattern to use in the HTML5 ``pattern `` attribute.
176
176
You usually don't need to specify this option because by default, the constraint
177
177
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]+.* ``).
180
180
181
181
However, there are some other incompatibilities between both patterns which
182
182
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
184
184
need to specify the HTML5 compatible pattern in the ``htmlPattern `` option:
185
185
186
186
.. configuration-block ::
@@ -197,7 +197,7 @@ need to specify the HTML5 compatible pattern in the ``htmlPattern`` option:
197
197
/**
198
198
* @Assert\Regex(
199
199
* pattern = "/^[a-z]+$/i",
200
- * htmlPattern = "^ [a-zA-Z]+$ "
200
+ * htmlPattern = "[a-zA-Z]+"
201
201
* )
202
202
*/
203
203
protected $name;
@@ -211,7 +211,7 @@ need to specify the HTML5 compatible pattern in the ``htmlPattern`` option:
211
211
name :
212
212
- Regex :
213
213
pattern : ' /^[a-z]+$/i'
214
- htmlPattern : ' ^ [a-zA-Z]+$ '
214
+ htmlPattern : ' [a-zA-Z]+'
215
215
216
216
.. code-block :: xml
217
217
@@ -225,7 +225,7 @@ need to specify the HTML5 compatible pattern in the ``htmlPattern`` option:
225
225
<property name =" name" >
226
226
<constraint name =" Regex" >
227
227
<option name =" pattern" >/^[a-z]+$/i</option >
228
- <option name =" htmlPattern" >^ [a-zA-Z]+$ </option >
228
+ <option name =" htmlPattern" >[a-zA-Z]+</option >
229
229
</constraint >
230
230
</property >
231
231
</class >
@@ -245,7 +245,7 @@ need to specify the HTML5 compatible pattern in the ``htmlPattern`` option:
245
245
{
246
246
$metadata->addPropertyConstraint('name', new Assert\Regex([
247
247
'pattern' => '/^[a-z]+$/i',
248
- 'htmlPattern' => '^ [a-zA-Z]+$ ',
248
+ 'htmlPattern' => '[a-zA-Z]+',
249
249
]));
250
250
}
251
251
}
0 commit comments