Skip to content

Commit 3d408ad

Browse files
author
valmonzo
committed
[Validator] Change preg_match condition on ContainsAlphanumericValidator
1 parent f679796 commit 3d408ad

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)