ID Card
The Polish national identity card number (numer dowodu osobistego) consists of three uppercase letters followed by six digits, where the final digit is a checksum computed using the ICAO 9303 weighted algorithm. The letters O and Q are excluded from the series.
use SlashLab\Numerik\Numerik;
// Boolean validationNumerik::idCard()->isValid('ABC123454'); // true
// Lowercase input and hyphens are stripped during normalisationNumerik::idCard()->isValid('abc-123-454'); // true
// Rich result$result = Numerik::idCard()->validate('ABC123454');$result->isValid; // true
// Parse to value object$idCard = Numerik::idCard()->parse('ABC123454');
// Null on failure instead of exception$idCard = Numerik::idCard()->tryParse('bad-input'); // nullValue object API
Section titled “Value object API”parse() returns a SlashLab\Numerik\ValueObjects\IdCard instance or throws on failure. tryParse() returns a SlashLab\Numerik\ValueObjects\IdCard instance or null if parsing fails.
| Method | Return type | Description |
|---|---|---|
getRaw() | string | The original input, untouched. |
getNormalized() | string | 3 uppercase letters + 6 digits, e.g. ABC123454. |
__toString() | string | Same as getNormalized(). |
Structure
Section titled “Structure”| Method | Return type | Description |
|---|---|---|
getSeries() | string | First 3 letters — the document series, e.g. ABC. |
getSequentialNumber() | string | 5-digit sequential number (positions 4–8), e.g. 12345. |
getCheckDigit() | string | Single check digit at position 9, e.g. 4. |
Examples
Section titled “Examples”$idCard = Numerik::idCard()->parse('ABC123454');
$idCard->getRaw(); // 'ABC123454'$idCard->getNormalized(); // 'ABC123454'$idCard->getSeries(); // 'ABC'$idCard->getSequentialNumber(); // '12345'$idCard->getCheckDigit(); // '4'
// Lowercase and hyphens normalise to the same value$idCard = Numerik::idCard()->parse('abc-123-454');
$idCard->getRaw(); // 'abc-123-454'$idCard->getNormalized(); // 'ABC123454'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 3 characters are letters; fail with
InvalidCharacters. - Assert the series contains no O or Q; fail with
InvalidFormat. - Assert characters 4–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. |
InvalidFormat | invalid_format | Series contains the letter O or Q. |
InvalidChecksum | invalid_checksum | ICAO 9303 check digit does not match. |
Related
Section titled “Related”
If this saved you time → ☕ Buy me a coffee