Passport
The Polish passport number consists of two uppercase letters followed by seven digits, where the final digit is a checksum computed using the ICAO 9303 weighted algorithm.
use SlashLab\Numerik\Numerik;
// Boolean validationNumerik::passport()->isValid('AB1234564'); // true
// Lowercase input and spaces are stripped during normalisationNumerik::passport()->isValid('ab 123456 4'); // true
// Rich result$result = Numerik::passport()->validate('AB1234564');$result->isValid; // true
// Parse to value object$passport = Numerik::passport()->parse('AB1234564');
// Null on failure instead of exception$passport = Numerik::passport()->tryParse('bad-input'); // nullValue object API
Section titled “Value object API”parse() returns a SlashLab\Numerik\ValueObjects\Passport instance or throws on failure. tryParse() returns a SlashLab\Numerik\ValueObjects\Passport instance or null if parsing fails.
| Method | Return type | Description |
|---|---|---|
getRaw() | string | The original input, untouched. |
getNormalized() | string | 2 uppercase letters + 7 digits, e.g. AB1234564. |
__toString() | string | Same as getNormalized(). |
Structure
Section titled “Structure”| Method | Return type | Description |
|---|---|---|
getSeries() | string | First 2 letters — the document series, e.g. AB. |
getSequentialNumber() | string | 6-digit sequential number (positions 3–8), e.g. 123456. |
getCheckDigit() | string | Single check digit at position 9, e.g. 4. |
Examples
Section titled “Examples”$passport = Numerik::passport()->parse('AB1234564');
$passport->getRaw(); // 'AB1234564'$passport->getNormalized(); // 'AB1234564'$passport->getSeries(); // 'AB'$passport->getSequentialNumber(); // '123456'$passport->getCheckDigit(); // '4'
// Lowercase and spaces normalise to the same value$passport = Numerik::passport()->parse('ab 123456 4');
$passport->getRaw(); // 'ab 123456 4'$passport->getNormalized(); // 'AB1234564'Validation algorithm
Section titled “Validation algorithm”- Reject inputs over 32 characters; fail with
InvalidLength. - Strip spaces and hyphens. Convert to uppercase.
- Assert exactly 9 characters remain; fail with
InvalidLength. - Assert the first 2 characters are letters; fail with
InvalidCharacters. - Assert characters 3–9 are digits; fail with
InvalidCharacters. - Apply the ICAO 9303 checksum over positions 1–8; fail with
InvalidChecksumif the result does not match position 9. See Algorithms.
Failure reasons
Section titled “Failure reasons”| Reason | Value | When |
|---|---|---|
InvalidLength | invalid_length | Number is not exactly 9 characters after normalisation, or raw input exceeds 32 characters. |
InvalidCharacters | invalid_characters | Non-letter characters in the series, or non-digit characters in the number portion. |
InvalidChecksum | invalid_checksum | ICAO 9303 check digit does not match. |
Related
Section titled “Related”
If this saved you time → ☕ Buy me a coffee