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()],
];
}
}
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.