Yii2 Brazilian Validators
Yii2 Extension that provide validators and features for brazilian localization, (*1)
- 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)
, (*2)
Installation
The preferred way to install this extension is through composer., (*3)
Either run, (*4)
php composer.phar require --prefer-dist yiibr/yii2-br-validator "*"
or add, (*5)
"yiibr/yii2-br-validator": "*"
to the require section of your composer.json
file., (*6)
Usage
Add the rules as the following example, (*7)
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()]
];
}
}