Skip to content

Commit ab0376b

Browse files
committed
minor #18972 [Validator] Change preg_match condition on ContainsAlphanumericValidator (Valmonzo)
This PR was merged into the 5.4 branch. Discussion ---------- [Validator] Change `preg_match` condition on `ContainsAlphanumericValidator` Hello there ! ✋🏽 I think following the Validator philosophy we prefer to check the regex this way, what do you think? Commits ------- 3d408ad [Validator] Change preg_match condition on ContainsAlphanumericValidator
2 parents f679796 + 3d408ad commit ab0376b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

validation/custom_constraint.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,14 @@ The validator class only has one required method ``validate()``::
117117
// ...
118118
}
119119

120-
if (!preg_match('/^[a-zA-Z0-9]+$/', $value, $matches)) {
121-
// the argument must be a string or an object implementing __toString()
122-
$this->context->buildViolation($constraint->message)
123-
->setParameter('{{ string }}', $value)
124-
->addViolation();
120+
if (preg_match('/^[a-zA-Z0-9]+$/', $value, $matches)) {
121+
return;
125122
}
123+
124+
// the argument must be a string or an object implementing __toString()
125+
$this->context->buildViolation($constraint->message)
126+
->setParameter('{{ string }}', $value)
127+
->addViolation();
126128
}
127129
}
128130

@@ -664,3 +666,4 @@ class to simplify writing unit tests for your custom constraints::
664666
// ...
665667
}
666668
}
669+

0 commit comments

Comments
 (0)