PHP code example of lumensistemas / br-validation
1. Go to this page and download the library: Download lumensistemas/br-validation 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/ */
lumensistemas / br-validation example snippets
use LumenSistemas\BrValidation\Cpf;
Cpf::isValid('856.981.040-77'); // true
Cpf::isValid('85698104077'); // true (raw form also accepted)
Cpf::isValid('11111111111'); // false (all-equal sequence)
Cpf::isValid(85698104077); // false (non-string input)
Cpf::format('85698104077'); // '856.981.040-77'
Cpf::normalize('856.981.040-77'); // '85698104077'
Cpf::generate(); // a valid 11-digit CPF
use LumenSistemas\BrValidation\Cnpj;
Cnpj::isValid('11.222.333/0001-81'); // true (legacy numeric)
Cnpj::isValid('12ABC34501DE35'); // true (alphanumeric, 2026 rules)
Cnpj::isValid('12abc34501de35'); // true (case-insensitive)
Cnpj::isValid('00000000000000'); // false (all-equal sequence)
Cnpj::format('11222333000181'); // '11.222.333/0001-81'
Cnpj::format('12abc34501de35'); // '12.ABC.345/01DE-35'
Cnpj::normalize(' 11.222.333/0001-81 '); // '11222333000181'
Cnpj::generateNumeric(); // a valid 14-digit numeric CNPJ
Cnpj::generateAlphanumeric(); // a valid alphanumeric CNPJ