Reputation: 6913
I'm using the Symfony 2.1 validation module to validate data for my REST API, it works correctly but I'm wondering if there is any easy way to validate items inside an array. For example, one of my fields is an array of dates, I want to ensure that each item inside is correctly formatted date.
I am using YAML as follows to set constraints, array_of_dates
is the field I'd like to be able to validate each item inside that array to be a valid date.
# src/Acme/DemoBundle/Resources/config/validation.yml
Acme\DemoBundle\Entity\Demo:
properties:
start:
- NotBlank: ~
- Date: ~
end:
- NotBlank: ~
- Date: ~
array_of_dates:
- Type:
type: array
Upvotes: 7
Views: 8396
Reputation: 3530
Apply All constraint validator.
This constraint allows you to apply a collection of constraints to each element of the array
Upvotes: 14