Valida que un valor es un código de país de dos letras válido.
Aplica a | propiedad o método |
Opciones | |
Clase | Symfony\Component\Validator\Constraints\Country |
Validador | Symfony\Component\Validator\Constraints\CountryValidator |
# src/UserBundle/Resources/config/validation.yml
Acme\UserBundle\Entity\User:
properties:
country:
- Country:
// src/Acme/UserBundle/Entity/User.php
namespace Acme\UserBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class User
{
/**
* @Assert\Country
*/
protected $country;
}
<!-- src/Acme/UserBundle/Resources/config/validation.xml -->
<class name="Acme\UserBundle\Entity\User">
<property name="country">
<constraint name="Country" />
</property>
</class>
// src/Acme/UserBundle/Entity/User.php
namespace Acme\UserBundle\Entity;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints as Assert;
class User
{
public static function loadValidationMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('country', new Assert\Country());
}
}