xxxxxxxxxx
use Symfony\Component\Validator\Validation;
use Symfony\Component\Validator\Constraints as Assert;
// Get the validator service
$validator = Validation::createValidator();
// Define your validation constraints
$constraints = new Assert\Collection([
'email' => [
new Assert\Email(),
new Assert\NotBlank(),
],
'message' => [
new Assert\Length([
'min' => 10,
'minMessage' => 'Your message should be at least {{ limit }} characters long',
]),
],
]);
// Validate the data
$violations = $validator->validate($data, $constraints);
if (count($violations) > 0) {
// There are validation errors, handle them
} else {
// The data is valid, continue with processing
}