yiibr/yii2-br-validator

Provide validations and features for brazilian localization

Installs: 84 334

Dependents: 7

Suggesters: 0

Security: 0

Stars: 14

Watchers: 6

Forks: 7

Open Issues: 1

Type:yii2-extension

1.1.1 2020-06-19 12:11 UTC

This package is auto-updated.

Last update: 2024-12-19 21:55:15 UTC


README

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
  • CEI: Cadastro específico no INSS (número de matrícula)

Yii2 Latest Stable Version Build Status Scrutinizer Code Quality Code Coverage Total Downloads

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 yiibr\brvalidator\CpfValidator;
use yiibr\brvalidator\CnpjValidator;
use yiibr\brvalidator\CeiValidator;

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

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