PHP code example of esponsor / dni-validator

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

    

esponsor / dni-validator example snippets


use Esponsor\DniValidator\RutChile;
use Esponsor\DniValidator\CurpMexico;

$rut = new RutChile();
$rut->validate('11.111.111-1'); // true
$rut->validate('11.111.111-2'); // false
$rut->clean('11.111.111-1');   // '111111111'
$rut->format('111111111');     // '11.111.111-1'

$curp = new CurpMexico();
$curp->validate('GICJ020605HDGRHNA2'); // true
$curp->format('gicj020605hdgrhna2');   // 'GICJ020605HDGRHNA2'

use Esponsor\DniValidator\Rules\RutChileRule;
use Esponsor\DniValidator\Rules\CurpMexicoRule;

$request->validate([
    'rut'  => ['

use Esponsor\DniValidator\DocumentValidatorRegistry;

$validator = DocumentValidatorRegistry::for('CL', 'RUT');
$validator->validate('11.111.111-1'); // true

DocumentValidatorRegistry::validate('MX', 'CURP', 'GICJ020605HDGRHNA2'); // true
DocumentValidatorRegistry::for('CL', 'UNKNOWN'); // null
bash
cd packages/php
composer install
./vendor/bin/pest
ts
import { getValidator } from '@esponsor/dni-validator';

const validator = getValidator('CL', 'RUT');
validator?.validate('11.111.111-1'); // true
validator?.format?.('111111111');    // '11.111.111-1'

getValidator('CL', 'UNKNOWN'); // null