Installation & Quick Start
Requirements
Section titled “Requirements”- PHP 8.3 or higher
- Composer
Installation
Section titled “Installation”-
Require the package
Terminal window composer require slashlab/numerik -
No configuration needed
The package is autoloaded via PSR-4. There is no service provider, config file, or bootstrap step for the core library.
-
Use it
use SlashLab\Numerik\Numerik;Numerik::pesel()->isValid('92060512186'); // true
Quick start
Section titled “Quick start”Boolean validation
Section titled “Boolean validation”use SlashLab\Numerik\Numerik;
Numerik::pesel()->isValid('92060512186'); // trueNumerik::idCard()->isValid('ABC123454'); // trueNumerik::passport()->isValid('AB1234564'); // trueNumerik::nip()->isValid('5260250274'); // trueNumerik::vatEu()->isValid('PL5260250274'); // trueNumerik::regon()->isValid('691761365'); // trueNumerik::krs()->isValid('0000127206'); // trueNumerik::nrb()->isValid('61102010260000000000000000'); // trueNumerik::iban()->isValid('PL61102010260000000000000000'); // trueRich validation result
Section titled “Rich validation result”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 messageSee Validation Results for the full API.
Parsing to a value object
Section titled “Parsing to a value object”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(); // trueUse tryParse() when you prefer null on failure instead of an exception:
$pesel = Numerik::pesel()->tryParse('bad-input'); // nullChoosing the right method
Section titled “Choosing the right method”| 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 |
Next steps
Section titled “Next steps”- Browse the PESEL, ID Card, Passport, NIP, VAT-EU, REGON, KRS, NRB, or IBAN reference for full method listings.
- Read Error Handling to understand the exception hierarchy.
- Read Validation Results for the complete
ValidationResultAPI. - Using Laravel? See the Laravel Integration guide for drop-in validation rules.
If this saved you time → ☕ Buy me a coffee