yii2-br-validator Yii2 Extension that provide validators and features for brazilian localization

  1. Yii2 Brazilian Validators
  2. Resources

Yii2 Brazilian Validators

Yii2 Extension that provide validators and features for brazilian localization

  • CPF: Cadastro de pessoa física (like a Security Social Numeber in USA)
  • CNPJ: Cadastro nacional de pessoa jurídica
Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist yiibr/yii2-br-validator "*"

or add

"yiibr/yii2-br-validator": "*"

to the require section of your composer.json file.

Usage

Add the rules as the following example

use Yii;
use yii\base\Model;
use leandrogehlen\brvalidator\CpfValidator;
use leandrogehlen\brvalidator\CnpjValidator;

class PersonForm extends Model
{
	public $name;
	public $cpf;
	public $cnpj;

	/**
	 * @return array the validation rules.
	 */
	public function rules()
	{
		return [
			// name is required
			['name', 'required'],
			// cpf validator
			['cpf', CpfValidator::className()],
			// cnpj validator
			['cnpj', CnpjValidator::className()],
		];
	}
}

Resources

1 0
1 follower
0 downloads
Yii Version: Unknown
License: BSD-2-Clause
Category: Validation
Developed by: leandrogehlen
Created on: Mar 8, 2014
Last updated: 4 years ago

Related Extensions