igorsantos07/yii-br-validator

This package is abandoned and no longer maintained. No replacement package was suggested.

Provide validations and features for brazilian localization on Yii 1.1.*

v1.0.4 2014-07-10 18:00 UTC

This package is auto-updated.

Last update: 2023-12-28 21:45:31 UTC


README

Superseeded by yii-br-pack Latest yii-br-pack stable version

Yii 1.1 Extension that provides validators for Brazilian localization.

  • CPF: Cadastro de Pessoa Física (like a Security Social Number in USA)
  • CNPJ: Cadastro Nacional de Pessoa Jurídica
  • landlines: beginning with 2 and 3
  • cellphones: 9 digits or 8 digits beginning with 7, 8 or 9

Installation

The preferred way to install this extension is through Composer.

Latest Stable Version Total Downloads

Either run this:

php composer.phar require --prefer-dist igorsantos07/yii-br-validator:1.*

or add this to the "require" section of your composer.json file.

"igorsantos07/yii-br-validator": "1.*"

Usage

Add the rules as the following example:

class PersonForm extends CModel {

  public $cpf;
  public $cnpj;
  public $cellphone;
  public $landline;
  public $phone;
  public $areaCode;

  // For maximum readability, you should create an alias for the validator folder :)
  // Here we are assuming you have at least an alias for your vendor folder.
  public function rules() {
    // Using short array notation but the class is PHP <5.4 compatible ;)
    return [
      // CPF validator
      ['cpf', 'vendor.igorsantos07.yii-br-validator.CpfValidator'],
      // CNPJ validator
      ['cnpj', 'vendor.igorsantos07.yii-br-validator.CnpjValidator'],
      // Cellphone-only validator, checking area code inside the field
      ['cellphone', 'vendor.igorsantos07.yii-br-validator.PhoneValidator', 'type' => PhoneValidator::TYPE_CELLPHONE],
      // Cellphone-only validator, not validating area code
      [
        'cellphone',
        'vendor.igorsantos07.yii-br-validator.PhoneValidator',
        'type'     => PhoneValidator::TYPE_CELLPHONE,
        'areaCode' => false
      ],
      // Landline-only validator
      ['landline', 'vendor.igorsantos07.yii-br-validator.PhoneValidator', 'type' => PhoneValidator::TYPE_LANDLINE],
      // Any phone validator - cellphone or landline
      ['phone', 'vendor.igorsantos07.yii-br-validator.PhoneValidator'],
      // Cellphone validator with external area code check
      [
        'cellphone',
        'vendor.igorsantos07.yii-br-validator.PhoneValidator',
        'type'              => PhoneValidator::TYPE_CELLPHONE,
        'areaCodeAttribute' => 'areaCode'
      ],
    ];
  }
}