Description
I have this example, which i use in a small json-api where i use the form component to handle requests and validation.
->add('account', 'text', [
'constraints' => [
new NotBlank(),
new Type('string'),
new Regex("/^XX\d+$/i")
]
])
I have a form field for an accountname. The format of this name is XX1234
.
The validation above works great if the data being validated is a string. If i pass in an array instead of the string i will get an exception that is originating from here:
In my opinion the validation should just fail here instead of throwing an exception. I pass an array in, and try to run an regexp on it. It seems obvious to me that something is wrong with the input data then and the validation should fail.
Other validation constraints seems to work this way. Look at this example:
->add('disksize', 'text', [
'constraints' => [
new NotBlank(),
new Type('numeric'),
new Range(['min' => 10, 'max' => 200])
]
])
This works. I get an validation error and no exceptions. Other validations contraints, like Length
seems to have the same problem as Regex
I think it would be great if all constraints just failed if they were passed an array if they cant handle an array. Or is there something i am overseeing?
Is there some way i can work around this to make it fail validation if i pass in an array?