0

Just wanted to know if this kind of assert exist in symfony (If not I will create it for my project).

Like I have an assert

#[AssertArrayRegex('/[0-9]{2}/')]
public array $variables = [];

This array would be validated

$array = [
'12',
'13'
]

But not this one

$array = [
'12',
'1'
]
1

1 Answer 1

2

you can put this code on your Entity Class :

#[Assert\All([
        new Assert\NotBlank,
        new Assert\Length(min: 2),
])]
$your_variable;

Or maybe this one :

#[Assert\All([
        new Assert\Regex('/[0-9]{2}/')
])]
$your_variable;

Regards

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.