Skip to content

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 validation
Numerik::passport()->isValid('AB1234564'); // true
// Lowercase input and spaces are stripped during normalisation
Numerik::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'); // null

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.

MethodReturn typeDescription
getRaw()stringThe original input, untouched.
getNormalized()string2 uppercase letters + 7 digits, e.g. AB1234564.
__toString()stringSame as getNormalized().
MethodReturn typeDescription
getSeries()stringFirst 2 letters — the document series, e.g. AB.
getSequentialNumber()string6-digit sequential number (positions 3–8), e.g. 123456.
getCheckDigit()stringSingle check digit at position 9, e.g. 4.
$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'
  1. Reject inputs over 32 characters; fail with InvalidLength.
  2. Strip spaces and hyphens. Convert to uppercase.
  3. Assert exactly 9 characters remain; fail with InvalidLength.
  4. Assert the first 2 characters are letters; fail with InvalidCharacters.
  5. Assert characters 3–9 are digits; fail with InvalidCharacters.
  6. Apply the ICAO 9303 checksum over positions 1–8; fail with InvalidChecksum if the result does not match position 9. See Algorithms.
ReasonValueWhen
InvalidLengthinvalid_lengthNumber is not exactly 9 characters after normalisation, or raw input exceeds 32 characters.
InvalidCharactersinvalid_charactersNon-letter characters in the series, or non-digit characters in the number portion.
InvalidChecksuminvalid_checksumICAO 9303 check digit does not match.
  • ID Card — same ICAO 9303 checksum algorithm; identifies the same person within Poland.
  • PESEL — universal personal identifier linked to the same individual.
If this saved you time → ☕ Buy me a coffee