3
votes

I'm using symfony2, i created a form with a field Timezone. My problem is i don't know how to validate this field. I can't find in the documentation "Validation Constraints Reference" an appropriate constraint.

1

1 Answers

3
votes

you have to make a custom constraint, here is how it works :

http://symfony.com/doc/current/cookbook/validation/custom_constraint.html

here is the logic for your validate() function:

if (in_array($timezone, DateTimeZone::listIdentifiers())) {
    echo "valid";
}
else {
    echo "invalid";
}