PHP code example of jeandepaula / country-validations

1. Go to this page and download the library: Download jeandepaula/country-validations 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/ */

    

jeandepaula / country-validations example snippets


   php artisan make:provider CountryValidationsServiceProvider
   

   

   namespace App\Providers;

   use Illuminate\Support\ServiceProvider;
   use CountryValidations\CountryValidator;

   class CountryValidationsServiceProvider extends ServiceProvider
   {
       public function register()
       {
           $this->app->singleton('country-validator', function () {
               return new CountryValidator();
           });
       }

       public function boot()
       {
           //
       }
   }
   

   'providers' => [
       // Other Service Providers...
       App\Providers\CountryValidationsServiceProvider::class,
   ],
   

   use Illuminate\Support\Facades\App;

   $validator = App::make('country-validator');

   // Validate CPF
   $isValidCpf = $validator->brazil()->personal()->cpf('123.456.789-09');
   

use CountryValidations\CountryValidator;

$validator = new CountryValidator();

$brazilValidator = $validator->brazil();

// Validate CPF
var_dump($brazilValidator->personal()->cpf('123.456.789-09'));

// Validate CNPJ
var_dump($brazilValidator->company()->cnpj('12.345.678/0001-95'));

// Validate Brazilian phone number
var_dump($brazilValidator->personal()->phone('(11) 98765-4321'));

// Validate vehicle plate
var_dump($brazilValidator->vehicle()->plate('ABC1234'));

$canadaValidator = $validator->canada();

// Validate SIN
var_dump($canadaValidator->personal()->sin('123-456-789'));

// Validate phone number
var_dump($canadaValidator->personal()->phone('(416) 555-2671'));

$usaValidator = $validator->usa();

// Validate SSN
var_dump($usaValidator->personal()->ssn('123-45-6789'));

// Validate driver's license
var_dump($usaValidator->personal()->driversLicense('A1234567', 'CA'));
bash
php vendor/bin/phpunit