Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallIn Node.js, you can check a Portuguese NIF locally by requiring a nine-digit string and verifying its final checksum digit. That confirms only that the number is structurally plausible: it does not prove that the tax number was assigned or that a business is registered for EU cross-border VAT. Use the European Commission’s VIES service for the latter check.
What a local NIF check can—and cannot—confirm
The Portuguese Tax and Customs Authority (AT) describes an individual NIF as nine digits: the first eight are sequential, and the ninth is a check digit. Its guidance also says a person’s NIF remains the same whether they are registered as a resident or non-resident. AT guidance on the NIF.
As an Amazon Associate I earn from qualifying purchases.
A checksum test can catch malformed input and many mistyped numbers. It cannot establish that the number was assigned to a taxpayer, is active, or belongs to the person presenting it. The European Commission’s separate TIN checker explicitly says its online check does not confirm a person’s identity or whether a TIN exists: Commission TIN guidance.
Implement the checksum in Node.js
The commonly documented Portuguese NIF checksum multiplies the first eight digits by weights 9 through 2, adds those products, and takes the sum modulo 11. If the remainder is 0 or 1, the check digit is 0; otherwise it is 11 minus the remainder. This formula is documented by technical references and package implementations; the AT guidance cited above establishes the check digit’s existence but does not publish this calculation.
#1 Best Overall
export function hasValidPortugueseNifChecksum(value) {
if (typeof value !== 'string' || !/^d{9}$/.test(value)) return false;
let sum = 0;
for (let i = 0; i < 8; i += 1) {
sum += Number(value[i]) * (9 - i);
}
const remainder = sum % 11;
const checkDigit = remainder < 2 ? 0 : 11 - remainder;
return Number(value[8]) === checkDigit;
}
The function accepts only a string of exactly nine ASCII digits. Keeping the NIF as a string avoids treating an identifier as a number and preserves any leading zero. If your application should accept spaces or separators, define and implement that input contract explicitly before calling the checksum function; do not silently delete arbitrary characters.
The function name is intentionally narrow: it validates a checksum, not assignment, taxpayer identity, or VAT registration. Prefix-based rules can reject some values, but prefix ranges are assignment-policy data and may change. The sources cited here do not provide a complete, current official AT prefix list, so do not present a locally maintained whitelist as AT-endorsed.
When to use VIES instead
For an EU business transaction, a NIF checksum is not a substitute for checking intra-EU VAT registration. The European Commission describes VIES as a search engine that queries national VAT databases, not as a database of its own. A valid result means VAT information exists in the relevant national data; an invalid result can mean the number does not exist, is not activated for intra-EU transactions, or registration is still being completed. A national system can also be temporarily unavailable, in which case retry rather than treating the service error as a definitive invalid result.
Recommended Free Tools
Use the European Commission’s VIES guidance and service for that registration question. The guidance page was last checked on 18 June 2026, and VIES covers EU member states listed there. When your tax controls require evidence, retain a record of a successful check. Do not describe VIES as identity verification.
Rank #3
Choose a local implementation or a package
A small local function is appropriate when you need a transparent structural check with a deliberately narrow input format. A dependency may be useful if it fits your project’s API, TypeScript needs, and input-normalization rules. The existence of a validator does not establish its ongoing maintenance or suitability for a particular legal or business workflow.
| Approach | What to evaluate | Evidence and limits |
|---|---|---|
| Local checksum function | Dependency footprint, accepted input, prefix policy, test coverage, and how the result is described to callers. | Implements structural plausibility only; it does not check assignment or current registration. |
pt-id |
Current release, license, tests, API behavior, and input normalization. | The npm registry page reviewed documents Portuguese identity-number validation, including a NIF validator, and showed version 1.2.0. That does not establish current maintenance or legal suitability: npm package page. |
| validator.js | Current release and whether its locale-specific behavior matches your requirements. | The reviewed 13.15.15 distributed source contains a pt-PT NIF check; this alone does not establish current compatibility or maintenance: validator.js source. |
| VIES lookup | Network availability, latency, service errors, registration semantics, and whether you need to retain a verification record. | Queries national VAT data for registration status; it is not a local checksum test or an identity check. |
For any dependency, check the latest release and license directly before adoption. Versions and service behavior can change.
Rank #4
Keep NIF, VAT, and EORI fields distinct
Portuguese tax-authority integration instructions specify the issuer NIF field without a country prefix. In separate guidance for international invoice customer identifiers, the country is represented in its own field. Follow the format required by the specific interface rather than accepting, stripping, or adding a prefix by assumption: AT NIF guidance and AT invoice manuals.
Free tools Windows power users keep installed
One-click scans. No signup required.
EORI is a different customs identifier. For Portuguese operators it is formed as PT plus the Portuguese NIF, but that does not make the prefixed value a NIF checksum input. Keep customs identifiers separate from VAT-number validation: European Commission EORI guidance.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




