I have a field in a request which can either be email or phone. Now I need to validate it against two constraints - the standard email constraint and a custom phone. I know that I can pass an array of constrains link this:
$constraint = new Constraints\Collection([
'name' => new Constraints\NotBlank(),
'uid' => [new Constraints\Email(), new Constraints\Phone()],
'pass' => new Constraints\NotBlank()
]);
But Validator applies the AND logic to the array of constraints, I need OR so that if the value fits one of them the validation succeeds. Is that possible by any standard Symfony means?
Create a custom validator and implement your own logic with existing constraint. AFAIK that's no other way to obtain what you're asking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With