PHP code example of slashlab / numerik
1. Go to this page and download the library: Download slashlab/numerik 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/ */
slashlab / numerik example snippets
use SlashLab\Numerik\Numerik;
// Simple boolean check
Numerik::pesel()->isValid('92060512186'); // true
Numerik::nip()->isValid('5260250274'); // true
// Rich validation result with failure reasons
$result = Numerik::pesel()->validate('92060512185'); // wrong checksum digit
$result->isFailed(); // true
$result->getFirstFailure()->reason; // ValidationFailureReason::InvalidChecksum
// Parse to value object
$pesel = Numerik::pesel()->parse('92060512186');
$pesel->getBirthDate()->format('Y-m-d'); // '1992-06-05'
$pesel->getGender(); // Gender::Female
// Try-parse — returns null on failure instead of throwing
$nip = Numerik::nip()->tryParse('5260250274');
$nip?->getFormatted(); // '526-025-02-74'
Numerik::nip(strict: false)->isValid('1111111111'); // true
Numerik::nip(strict: true)->isValid('1111111111'); // false — all-same-digit