Skip to content

NIP

NIP (Numer Identyfikacji Podatkowej) is Poland’s 10-digit tax identification number, used by both individuals and legal entities.

use SlashLab\Numerik\Numerik;
// Boolean
Numerik::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'); // null

NIP accepts hyphens and spaces as separators in the input:

Numerik::nip()->isValid('526-025-02-74'); // true
Numerik::nip()->isValid('526 025 02 74'); // true

parse() and tryParse() return a SlashLab\Numerik\ValueObjects\Nip instance.

MethodReturn typeDescription
getRaw()stringThe original input, untouched.
getNormalized()string10 raw digits (hyphens and spaces removed).
__toString()stringSame as getNormalized().
MethodReturn typeDescription
getFormatted()stringCanonical NNN-NNN-NN-NN display form.
getFormattedAlternative()stringAlternative NNN-NN-NN-NNN display form used by some legal entity documents.
getTaxOfficeCode()stringFirst 3 digits — indicates the issuing tax office.
$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'
ReasonValueWhen
InvalidLengthinvalid_lengthInput is not exactly 10 digits after stripping separators.
InvalidCharactersinvalid_charactersCharacters other than digits, hyphens, and spaces are present.
InvalidFormatinvalid_formatFirst 3 digits are 000 (no valid tax office has code 000).
InvalidChecksuminvalid_checksumChecksum digit does not match.
AllSameDigitall_same_digitAll digits are identical — strict mode only.

Weights: 6, 5, 7, 2, 3, 4, 5, 6, 7

  1. Strip hyphens and spaces. Assert exactly 10 digits.
  2. Assert the first 3 digits are not 000.
  3. Multiply each of the first 9 digits by its weight, sum, take mod 11. The result must equal digit 10. If the modulo result is 10, the number is structurally invalid — no valid NIP can have a checksum digit of 10.

See Algorithms for the full reference.

If this saved you time → ☕ Buy me a coffee