igorsantos07 / yii-br-validator
Provide validations and features for brazilian localization on Yii 1.1.*
Installs: 48
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 9
Open Issues: 0
Type:yii-extension
Requires
- yiisoft/yii: 1.1.*
Requires (Dev)
- phpunit/phpunit: 3.7.*
Suggests
- igorsantos07/yii-br-pack: Superseeded by this package, that also offers some masked fields and more stuff
README
Superseeded by
yii-br-pack
Yii 1.1 Extension that provides validators for Brazilian localization.
- CPF: Cadastro de Pessoa Física (like a Security Social Number in USA)
- CNPJ: Cadastro Nacional de Pessoa Jurídica
- landlines: beginning with 2 and 3
- cellphones: 9 digits or 8 digits beginning with 7, 8 or 9
Installation
The preferred way to install this extension is through Composer.
Either run this:
php composer.phar require --prefer-dist igorsantos07/yii-br-validator:1.*
or add this to the "require" section of your composer.json
file.
"igorsantos07/yii-br-validator": "1.*"
Usage
Add the rules as the following example:
class PersonForm extends CModel { public $cpf; public $cnpj; public $cellphone; public $landline; public $phone; public $areaCode; // For maximum readability, you should create an alias for the validator folder :) // Here we are assuming you have at least an alias for your vendor folder. public function rules() { // Using short array notation but the class is PHP <5.4 compatible ;) return [ // CPF validator ['cpf', 'vendor.igorsantos07.yii-br-validator.CpfValidator'], // CNPJ validator ['cnpj', 'vendor.igorsantos07.yii-br-validator.CnpjValidator'], // Cellphone-only validator, checking area code inside the field ['cellphone', 'vendor.igorsantos07.yii-br-validator.PhoneValidator', 'type' => PhoneValidator::TYPE_CELLPHONE], // Cellphone-only validator, not validating area code [ 'cellphone', 'vendor.igorsantos07.yii-br-validator.PhoneValidator', 'type' => PhoneValidator::TYPE_CELLPHONE, 'areaCode' => false ], // Landline-only validator ['landline', 'vendor.igorsantos07.yii-br-validator.PhoneValidator', 'type' => PhoneValidator::TYPE_LANDLINE], // Any phone validator - cellphone or landline ['phone', 'vendor.igorsantos07.yii-br-validator.PhoneValidator'], // Cellphone validator with external area code check [ 'cellphone', 'vendor.igorsantos07.yii-br-validator.PhoneValidator', 'type' => PhoneValidator::TYPE_CELLPHONE, 'areaCodeAttribute' => 'areaCode' ], ]; } }