PHP code example of jamacio / document-validator
1. Go to this page and download the library: Download jamacio/document-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/ */
jamacio / document-validator example snippets
bash
use Jamacio\DocumentValidator;
// Example for CPF:
$cpf = "123.456.789-09";
if (DocumentValidator::isCPF($cpf)) {
echo "Formatted CPF: " . DocumentValidator::formatCPF($cpf) . "\n";
echo "CPF is " . (DocumentValidator::validateCPF($cpf) ? "valid" : "invalid") . "\n";
}
// Example for CNPJ:
$cnpj = "12.345.678/0001-95";
if (DocumentValidator::isCNPJ($cnpj)) {
echo "Formatted CNPJ: " . DocumentValidator::formatCNPJ($cnpj) . "\n";
echo "CNPJ is " . (DocumentValidator::validateCNPJ($cnpj) ? "valid" : "invalid") . "\n";
}
// Generic document validation:
$document = "12345678909";
echo "Document " . $document . " is " . (DocumentValidator::validateDocument($document) ? "valid" : "invalid") . "\n";