ideup/extra-validator-bundle

此包最新版本(dev-master)的许可信息不可用。

西班牙邮政编码和个人身份验证的Symfony2验证器

安装数: 7,749

依赖: 0

建议者: 0

安全性: 0

星标: 9

关注者: 3

分叉: 9

开放问题: 0

类型:symfony-bundle

dev-master 2015-01-04 17:41 UTC

This package is not auto-updated.

Last update: 2024-09-24 08:19:37 UTC


README

此包包含了一组有用的验证器和断言,可用于您的项目中。

包含的断言/验证器

  • DNI(DNI/NIF文件)
  • 电话(电话号码,通过正则表达式)
  • 移动电话(移动电话号码)
  • 带前缀的电话(带国际前缀的电话号码)

如何包含ExtraValidator

在您的composer.json中

"require": {
  "ideup/extra-validator-bundle": "dev-master"
}

...并在您的AppKernel.php文件中

<?php
public function registerBundles()
{
    $bundles = array(
      ...
        new Ideup\ExtraValidatorBundle\IdeupExtraValidatorBundle(),
      );
}

如何在表单/实体中使用ExtraValidator

<?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;

  ...
}

您可以在实体/表单中使用AssertExtraAssert验证器

<?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验证器不会修改symfony的正则断言,我们只是添加了一组有用的新验证器,使我们的生活更加便捷!

作者

  • javiacei
  • Moisés Maciá