title: Symfony2 : Form Validation with Collection
body: <p>I use assert to check values of my form. I am not able to work with assert on a collection. The main goal it to check if each values are not empty and is a number.</p>
  
  <p>I tried to use <a href="http://symfony.com/doc/current/reference/constraints/Collection.html" rel="nofollow">this link</a> to solve my issue without success.</p>
  
  <p>Here is part of my entity :</p>
  
  <pre><code>namespace MyBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Doctrine\Common\Collections\ArrayCollection;
  use Symfony\Component\Validator\Constraints as Assert;
  
  class Myclass
  {
  
      private $id;    
      /**
       * @Assert\NotBlank()
       * @Assert\Regex(pattern="/^0[1-9]([-. ]?[0-9]{2}){4}$/",message="Invalid")
       */
      private $numbers;
  
      ...
  
  
  
      public function __construct()
      {
          $this-&gt;numbers= new ArrayCollection();
      }
  
      ...
  
      public function addNumber($number)
      {
          $this-&gt;numbers[] = $number;
          return $this;
      }
  
      public function removeNumber($number)
      {
          $this-&gt;numbers-&gt;removeElement($number);
      }
  
      public function getNumbers()
      {
          return $this-&gt;numbers;
      }
  }
  </code></pre>
  
  <p>And here is a part of my form : </p>
  
  <pre><code>namespace MyBundle\Form;
  
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\OptionsResolver\OptionsResolver;
  
  class MyclassType extends AbstractType
  {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
  
          $builder
          -&gt;add('numbers',"Symfony\Component\Form\Extension\Core\Type\CollectionType",array(
              'required'=&gt;true,
              'prototype' =&gt; true,
              'allow_add' =&gt; true,            
              'allow_delete' =&gt; true,
              'entry_type'=&gt;"Symfony\Component\Form\Extension\Core\Type\TextType",
              'entry_options'   =&gt; array(
                  'required'  =&gt; true,
                  'attr'      =&gt; array('class' =&gt; 'form-control'),
                  )
              )
          );
      }
  
      public function configureOptions(OptionsResolver $resolver)
      {
          $resolver-&gt;setDefaults(array(
            'data_class' =&gt; 'MyBundle\Entity\Myclass'
          ));
      }
  
      public function getBlockPrefix()
      {
          return 'mybundle_myclass';
      }
  }
  </code></pre>