NIP
NIP (Numer Identyfikacji Podatkowej) is Poland’s 10-digit tax identification number, used by both individuals and legal entities.
use SlashLab\Numerik\Numerik;
// BooleanNumerik::nip()->isValid('5260250274'); // true
// Rich result$result = Numerik::nip()->validate('5260250274');$result->isValid; // true
// Parse to value object$nip = Numerik::nip()->parse('5260250274');
// Null on failure instead of exception$nip = Numerik::nip()->tryParse('bad-input'); // nullNIP accepts hyphens and spaces as separators in the input:
Numerik::nip()->isValid('526-025-02-74'); // trueNumerik::nip()->isValid('526 025 02 74'); // trueValue object API
Section titled “Value object API”parse() and tryParse() return a SlashLab\Numerik\ValueObjects\Nip instance.
| Method | Return type | Description |
|---|---|---|
getRaw() |
string |
The original input, untouched. |
getNormalized() |
string |
10 raw digits (hyphens and spaces removed). |
__toString() |
string |
Same as getNormalized(). |
Formatting & metadata
Section titled “Formatting & metadata”| Method | Return type | Description |
|---|---|---|
getFormatted() |
string |
Canonical NNN-NNN-NN-NN display form. |
getFormattedAlternative() |
string |
Alternative NNN-NN-NN-NNN display form used by some legal entity documents. |
getTaxOfficeCode() |
string |
First 3 digits — indicates the issuing tax office. |
Examples
Section titled “Examples”$nip = Numerik::nip()->parse('5260250274');
$nip->getRaw(); // '5260250274'$nip->getNormalized(); // '5260250274'$nip->getFormatted(); // '526-025-02-74'$nip->getFormattedAlternative(); // '526-02-50-274'$nip->getTaxOfficeCode(); // '526'
// With formatted input$nip = Numerik::nip()->parse('526-025-02-74');$nip->getRaw(); // '526-025-02-74'$nip->getNormalized(); // '5260250274'Failure reasons
Section titled “Failure reasons”| Reason | Value | When |
|---|---|---|
InvalidLength |
invalid_length |
Input is not exactly 10 digits after stripping separators. |
InvalidCharacters |
invalid_characters |
Characters other than digits, hyphens, and spaces are present. |
InvalidFormat |
invalid_format |
First 3 digits are 000 (no valid tax office has code 000). |
InvalidChecksum |
invalid_checksum |
Checksum digit does not match. |
AllSameDigit |
all_same_digit |
All digits are identical — strict mode only. |
Validation algorithm
Section titled “Validation algorithm”Weights: 6, 5, 7, 2, 3, 4, 5, 6, 7
- Strip hyphens and spaces. Assert exactly 10 digits.
- Assert the first 3 digits are not
000. - Multiply each of the first 9 digits by its weight, sum, take
mod 11. The result must equal digit 10; since a single digit can only be 0–9, a modulo result of10can never match and always fails withInvalidChecksum.
See Algorithms for the full reference.
If this saved you time → ☕ Buy me a coffee