PHP code example of safeaccess / identum

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

    

safeaccess / identum example snippets


function validateCpf(string $cpf): bool {
    $cpf = preg_replace('/\D/', '', $cpf);
    if (strlen($cpf) !== 11 || preg_match('/(\d)\1{10}/', $cpf)) return false;
    // 30+ lines: loops, hardcoded weights, manual digit comparison...
}

Identum::cpf('529.982.247-25')->isValid();                    // true
Identum::ie('343.173.196.450', StateEnum::SP)->isValid();     // true — all 27 states

use SafeAccess\Identum\Identum;
use SafeAccess\Identum\Assets\IE\StateEnum;
use SafeAccess\Identum\Exceptions\ValidationException;

// Boolean shortcut — formatting stripped automatically
Identum::cpf('529.982.247-25')->isValid();                       // true
Identum::cnpj('84.773.274/0001-03')->isValid();                  // true
Identum::cnpj('A0000000000032')->isValid();                      // true — alphanumeric CNPJ
Identum::cnh('22522791508')->isValid();                          // true
Identum::cep('78000-000')->isValid();                            // true
Identum::cns('100000000060018')->isValid();                      // true
Identum::pis('329.9506.158-9')->isValid();                       // true
Identum::ie('343.173.196.450', StateEnum::SP)->isValid();        // true — all 27 states
Identum::renavam('60390908553')->isValid();                      // true
Identum::placa('ABC1D23')->isValid();                            // true — Mercosul format
Identum::tituloEleitor('123456781295')->isValid();               // true
Identum::cartao('4111111111111111')->isValid();                  // true — Luhn
Identum::pix('[email protected]')->isValid();                       // true — PIX key
Identum::certidao('00188301551987100018050000056665')->isValid();// true — certificate

// Rich result — why it failed, the normalized value, and extracted metadata
$result = Identum::cpf('529.982.247-25')->validate();
$result->valid;       // true
$result->reason;      // null (a ReasonCode enum when invalid)
$result->normalized;  // '52998224725'
$result->meta?->uf;   // 'SP' — fiscal region

// Validate or throw — the exception carries structured context
try {
    Identum::cpf('000.000.000-00')->validateOrFail();
} catch (ValidationException $e) {
    $e->document;   // 'cpf'
    $e->reason;     // ReasonCode::KnownInvalid
    $e->normalized; // '00000000000'
}

// Allow list / deny list (format-agnostic)
Identum::cpf('529.982.247-25')->denyList(['52998224725'])->isValid();   // false
Identum::cpf('000.000.000-00')->allowList(['000.000.000-00'])->isValid(); // true

// Format / strip / generate
Identum::cpf('52998224725')->format();      // '529.982.247-25'
Identum::cpf('529.982.247-25')->strip();    // '52998224725'
Identum::generateCpf();                      // e.g. '76502099010'
Identum::generateCnpj(formatted: true);      // e.g. '12.345.678/0001-95'

use SafeAccess\Identum\Assets\CPF\CPFValidation;

$validator = new CPFValidation('529.982.247-25');
$validator->isValid(); // true

use SafeAccess\Identum\Assets\IE\StateEnum;

Identum::ie('153189458', StateEnum::BA)->isValid();    // Bahia — Mod-10/11 dual
Identum::ie('7908930932562', StateEnum::MG)->isValid(); // Minas Gerais
Identum::ie('P199163724045', StateEnum::SP)->isValid(); // São Paulo rural (P prefix)

Identum::cnpj('A0000000000032')->isValid(); // true — alphanumeric CNPJ

// Payment card — Luhn integrity only; meta.brand is best-effort BIN detection
Identum::cartao('4111111111111111')->validate()->meta?->brand; // 'visa'

// PIX — any of the five DICT key types; meta.keyType tells which
Identum::pix('+5510998765432')->validate()->meta?->keyType;    // 'phone'

// Civil-registry certificate — 32-digit matrícula (Mod-11 ×10)
Identum::certidao('00188301551987100018050000056665')->validate()->meta?->type; // 'birth'