Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

How to Validate Portuguese NIFs in Node.js

A Node.js checksum function can validate a Portuguese NIF’s structure, but only VIES can check whether a business is registered for intra-EU VAT.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In 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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.