PHPackages                             igorsantos07/yii-br-pack - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. igorsantos07/yii-br-pack

AbandonedYii-extension[Validation &amp; Sanitization](/categories/validation)

igorsantos07/yii-br-pack
========================

Provide validations and easy masked fields for brazilian localization on Yii 1.1.\*

v1.2.1(11y ago)1301[1 issues](https://github.com/igorsantos07/yii-br-pack/issues)BSD-3-ClausePHP

Since Jul 10Pushed 11y ago1 watchersCompare

[ Source](https://github.com/igorsantos07/yii-br-pack)[ Packagist](https://packagist.org/packages/igorsantos07/yii-br-pack)[ RSS](/packages/igorsantos07-yii-br-pack/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (2)Versions (6)Used By (0)

Yii Brazilian Package
=====================

[](#yii-brazilian-package)

Yii 1.1 Extension that provides various helpers for Brazilian localization.

- Validators:
    - 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
- Fields:
    - CPF and CNPJ
    - Polymorphic credit card field - given the name it turns into a PAN, CVV or Expiry field
    - Phone - landline, mobile, both, or area code only
- Formatter:
    - CPF
    - Phone with area code
    - Money (alias of `NumberFormatter::formatCurrency()` which defaults to BRL

Installation
------------

[](#installation)

The preferred way to install this extension is through [Composer](http://getcomposer.org/download/).

[![Latest Stable Version](https://camo.githubusercontent.com/01d8a6c44d06eae8a9b588fc78cc0a56412737f3c56d46f7d432ab2711c1e86a/68747470733a2f2f706f7365722e707567782e6f72672f69676f7273616e746f7330372f7969692d62722d7061636b2f762f737461626c652e737667)](https://packagist.org/packages/igorsantos07/yii-br-pack)[![Total Downloads](https://camo.githubusercontent.com/2862e6311785ee9375126ed703217261d251ad3ec0b6460f610edcb9deb8c881/68747470733a2f2f706f7365722e707567782e6f72672f69676f7273616e746f7330372f7969692d62722d7061636b2f646f776e6c6f6164732e737667)](https://packagist.org/packages/igorsantos07/yii-br-pack)

Either run this:

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

```

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

```
"igorsantos07/yii-br-pack": "1.*"

```

Usage
-----

[](#usage)

Add the rules as the following example:

> models/PersonForm.php

```
class PersonForm extends CModel {

  public $name;

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

  public $card_number;
  public $card_cvv;
  public $card_expiry;

  public function rules() {
    // Using short array notation but the class is PHP  PhoneValidator::TYPE_CELLPHONE],
      // Cellphone-only validator, not validating area code
      [
        'cellphone',
        'BrPack\Validator\Phone',
        'type'     => BrPack\Validator\Phone::TYPE_CELLPHONE,
        'areaCode' => false
      ],
      // Landline-only validator
      ['landline', 'BrPack\Validator\Phone', 'type' => BrPack\Validator\Phone::TYPE_LANDLINE],
      // Any phone validator - cellphone or landline
      ['phone', 'BrPack\Validator\Phone'],
      // Cellphone validator with external area code check
      [
        'cellphone',
        'BrPack\Validator\Phone',
        'type'              => BrPack\Validator\Phone::TYPE_CELLPHONE,
        'areaCodeAttribute' => 'areaCode'
      ],
    ];
  }
}
```

> views/person/edit.php

```
