The Country Validations Library is a powerful PHP package designed to validate various data formats for Brazil, Canada, and the USA. The library provides easy-to-use methods for personal, corporate, banking, and vehicle data validation.
- Brazil: Validates CPF, CNPJ, phone numbers, bank account details, vehicle plates, and more.
- Canada: Validates SIN, phone numbers, and driver's licenses.
- USA: Validates SSN, phone numbers, passports, and driver's licenses.
- Personal data validation (e.g., CPF, SIN, SSN, email, name).
- Banking data validation (e.g., IBAN, SWIFT, bank codes).
- Vehicle data validation (e.g., plates, VIN, RENAVAM).
- Corporate data validation (e.g., CNPJ, state registration, NIRE).
- Easy configuration and modular structure.
composer require jeandepaula/country-validations
- PHP 7.4 or higher
- Composer
If needed, you can create a service provider to encapsulate the library.
-
Create a Service Provider
php artisan make:provider CountryValidationsServiceProvider
-
Register the Library in the Provider In the generated
CountryValidationsServiceProvider
:<?php 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() { // } }
-
Add the Provider in
config/app.php
'providers' => [ // Other Service Providers... App\Providers\CountryValidationsServiceProvider::class, ],
-
Using the Library in Controllers
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'));
- Personal: CPF, RG, CNS, email, phone, birth date, full name, PIS/PASEP, CNH, voter registration.
- Company: CNPJ, corporate name, corporate phone, state registration, NIRE.
- Bank: Bank code, branch code, account number, boleto line, SWIFT, IBAN, BIN.
- Vehicle: Plate (standard and Mercosul), RENAVAM, VIN (chassis), vehicle category.
- Currency: Brazilian Real format, exchange rates, positive amounts, limits, numeric format, percentages.
- Personal: SIN, email, phone, birth date, full name, passport, driver's license (by province).
- Personal: SSN, email, phone, birth date, full name, passport, driver's license (by state).
Run the tests using PHPUnit:
php vendor/bin/phpunit
This library is open-sourced software licensed under the MIT license.
For any questions or support, please reach out to Jean de Paula.