@@ -175,12 +175,12 @@ Options
175175This option specifies the pattern to use in the HTML5 ``pattern `` attribute.
176176You usually don't need to specify this option because by default, the constraint
177177will 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
181181However, there are some other incompatibilities between both patterns which
182182cannot 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
184184need 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