Yii 2 Validator
Yii2 Extension that provide validations and features for Brazilian and Portugal localization, (*1)
- CPF: Cadastro de pessoa fĆsica (BR)
- CNPJ: Cadastro nacional de pessoa jurĆdica (BR)
- CEI: Cadastro especĆfico no INSS (BR)
- NIF: NĆŗmero de identificaĆ§Ć£o fiscal (PT)
, (*2)
Installation
The preferred way to install this extension is through composer., (*3)
Either run, (*4)
php composer.phar require --prefer-dist rafaelrabaco/yii2-validator "*"
or add, (*5)
"rafaelrabaco/yii2-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 rafaelrabaco\validator\CpfValidator;
use rafaelrabaco\validator\CnpjValidator;
use rafaelrabaco\validator\CeiValidator;
use rafaelrabaco\validator\NifValidator;
class PersonForm extends Model
{
public $name;
public $cpf;
public $cnpj;
public $cei;
public $nif;
/**
* @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()]
// nif validator
['nif', NifValidator::className()]
];
}
}