igorsantos07 / yii-br-validator
此包已被废弃,不再维护。未建议替代包。
为 Yii 1.1.* 提供巴西本地化的验证和功能。
v1.0.4
2014-07-10 18:00 UTC
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
已被
yii-br-pack
替代
提供巴西本地化验证器的 Yii 1.1 扩展。
- CPF: 个人身份登记(类似于美国的社保号码)
- CNPJ: 法人登记
- 固定电话:以2或3开头
- 移动电话:9位数字或以7、8或9开头的8位数字
安装
安装此扩展的首选方式是通过 Composer。
运行以下命令
php composer.phar require --prefer-dist igorsantos07/yii-br-validator:1.*
或将以下内容添加到您的 composer.json
文件的 "require" 部分。
"igorsantos07/yii-br-validator": "1.*"
使用
按照以下示例添加规则
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' ], ]; } }