PHP code example of igorsantos07 / yii-br-validator

1. Go to this page and download the library: Download igorsantos07/yii-br-validator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

igorsantos07 / yii-br-validator example snippets


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'
      ],
    ];
  }
}

php composer.phar