This package contains a set of useful validators and asserts to use in your projects.
- DNI (DNI/NIF documents)
- Phone (phone numbers, by regular expresions)
- MobilePhone (mobile phone numbers)
- PrefixedPhone (phone numbers with international prefix)
You should clone this repository in your Symfony's vendor/bundles
directory, add it into autoload.php
file:
<?php
$loader->registerNamespaces(array(
'Symfony' => array(__DIR__.'/../vendor/symfony/src', __DIR__.'/../vendor/bundles'),
...
'Ideup' => __DIR__.'/../vendor/bundles',
);
... and in your AppKernel.php
file:
<?php
public function registerBundles()
{
$bundles = array(
...
new Ideup\ExtraValidatorBundle\ExtraValidatorBundle(),
);
}
<?php
namespace Acme\AcmeDemoBundle\Entity;
use Ideup\ExtraValidatorBundle\Validator as ExtraAssert;
class AcmeEntity {
/**
* @ExtraAssert\MobilePhone(message="Your mobile phone number is not valid")
*/
protected $phone;
...
}
You can use both Assert
and ExtraAssert
validators in your entities/forms:
<?php
namespace Acme\AcmeDemoBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
use Ideup\ExtraValidatorBundle\Validator as ExtraAssert;
class AcmeEntity {
/**
* @Assert\NotBlank(message="You have to input a phone number")
* @ExtraAssert\MobilePhone(message="Your mobile phone number is not valid")
*/
protected $phone;
...
}
ExtraAssert
validators do not modify symfony's regular asserts, we just add a bunch of useful set of new validators to
make our lives easy!
- javiacei
- Moisés Maciá