Skip to content

Installation & Quick Start

  • PHP 8.3 or higher
  • Composer
  1. Require the package

    Terminal window
    composer require slashlab/numerik
  2. No configuration needed

    The package is autoloaded via PSR-4. There is no service provider, config file, or bootstrap step for the core library.

  3. Use it

    use SlashLab\Numerik\Numerik;
    Numerik::pesel()->isValid('92060512186'); // true
use SlashLab\Numerik\Numerik;
Numerik::pesel()->isValid('92060512186'); // true
Numerik::idCard()->isValid('ABC123454'); // true
Numerik::passport()->isValid('AB1234564'); // true
Numerik::nip()->isValid('5260250274'); // true
Numerik::vatEu()->isValid('PL5260250274'); // true
Numerik::regon()->isValid('691761365'); // true
Numerik::krs()->isValid('0000127206'); // true
Numerik::nrb()->isValid('61102010260000000000000000'); // true
Numerik::iban()->isValid('PL61102010260000000000000000'); // true

validate() never throws. It returns a ValidationResult that carries the list of failures when validation does not pass.

use SlashLab\Numerik\Numerik;
$result = Numerik::pesel()->validate('92060512186');
$result->isValid; // true
$result->failures; // []
$result = Numerik::pesel()->validate('00000000000');
$result->isFailed(); // true
$result->getFirstFailure()->reason->value; // 'all_zeros'
$result->getFirstFailure()->message; // human-readable message

See Validation Results for the full API.

On success, parse() returns a value object. On failure, it throws a ValidationException.

use SlashLab\Numerik\Numerik;
$pesel = Numerik::pesel()->parse('92060512186');
$pesel->getBirthDate()->format('Y-m-d'); // '1992-06-05'
$pesel->getGender(); // Gender::Female
$pesel->getAge(); // int — calculated from today
$pesel->isAdult(); // true

Use tryParse() when you prefer null on failure instead of an exception:

$pesel = Numerik::pesel()->tryParse('bad-input'); // null
Method Returns Throws Use when
isValid() bool never Simple existence check
validate() ValidationResult never You need the failure reason
parse() value object ValidationException You need extracted data and want exceptions
tryParse() value object or null never You need extracted data but prefer null over exceptions
If this saved you time → ☕ Buy me a coffee