Skip to content
Yii2 Extension that provide validations and features for brazilian localization
PHP JavaScript
Branch: master
Clone or download
Pull request Compare This branch is 16 commits ahead, 47 commits behind yiibr:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Yii Brazilian Validators

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


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.*"


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
        '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
        'type'              => PhoneValidator::TYPE_CELLPHONE,
        'areaCodeAttribute' => 'areaCode'
You can’t perform that action at this time.