7

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
1
  • 2
    You would have to write your own custom constraint Commented Dec 11, 2012 at 21:08

1 Answer 1

14

Apply All constraint validator.

This constraint allows you to apply a collection of constraints to each element of the array

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

1 Comment

Thanks. A combination of that, and the suggestion in the comment from Squazic should do what I need.

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.