Skip to content

Commit d4e53a3

Browse files
committed
Merge branch '5.4' into 6.3
* 5.4: [Validator] Change preg_match condition on ContainsAlphanumericValidator
2 parents 62ec3cd + ab0376b commit d4e53a3

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
@@ -121,12 +121,14 @@ The validator class only has one required method ``validate()``::
121121
// ...
122122
}
123123

124-
if (!preg_match('/^[a-zA-Z0-9]+$/', $value, $matches)) {
125-
// the argument must be a string or an object implementing __toString()
126-
$this->context->buildViolation($constraint->message)
127-
->setParameter('{{ string }}', $value)
128-
->addViolation();
124+
if (preg_match('/^[a-zA-Z0-9]+$/', $value, $matches)) {
125+
return;
129126
}
127+
128+
// the argument must be a string or an object implementing __toString()
129+
$this->context->buildViolation($constraint->message)
130+
->setParameter('{{ string }}', $value)
131+
->addViolation();
130132
}
131133
}
132134

@@ -547,3 +549,4 @@ class to simplify writing unit tests for your custom constraints::
547549
// ...
548550
}
549551
}
552+

0 commit comments

Comments
 (0)