GLN Validation in Node.js — GS1 Check Digit and Prefix Lookup
GLN (Global Location Number) is the GS1 standard for identifying physical and digital locations in supply chains. Here's how the check digit works, what the prefix encodes, and how to validate GLNs reliably in your Node.js application.
In this guide
1. What is a GLN?
GLN stands for Global Location Number — a 13-digit identifier managed by GS1, the same standards body behind EAN barcodes and GTINs. While EAN identifies products, GLN identifies locations: warehouses, retail stores, loading docks, hospital departments, or even digital endpoints like EDI mailboxes.
Every participant in a GS1-enabled supply chain — from manufacturers to retailers to logistics providers — uses GLNs to unambiguously identify where goods are shipped from, shipped to, and stored. GLNs appear in purchase orders, advance shipping notices (ASN), invoices, and GS1-128 barcodes on pallet labels.
A single company can have hundreds of GLNs — one for headquarters, one per warehouse, one per department — all sharing the same GS1 company prefix but with different location references.
2. GLN structure — 13 digits decoded
| Segment | 061 | 4141 | 00003 | 6 | |||||||||
| Role | GS1 Prefix | Company | Location Ref | Check | |||||||||
GS1 Prefix (2–3 digits) — identifies the GS1 Member Organisation that assigned the company prefix. For example, 061 is assigned to GS1 US.
Company Prefix (variable) — uniquely identifies the company within the GS1 system. The length varies (4–8 digits) depending on how many identifiers the company needs.
Location Reference (variable) — assigned by the company to identify a specific location: a warehouse, a store, a department, or a digital endpoint.
Check Digit (1 digit) — computed using the GS1 mod-10 algorithm with alternating weights of 1 and 3. Catches single-digit errors and most transpositions.
3. GS1 check digit algorithm — alternating weights 1 and 3
GLN uses the same check digit algorithm as EAN-13 and GTIN — alternating weights of 1 and 3, applied right-to-left (or equivalently, starting with weight 3 at position 1 from the left for a 13-digit number).
Let's walk through 0614141000036:
Step 1 — Apply alternating weights (1 and 3) to the first 12 digits
| Digit | 0 | 6 | 1 | 4 | 1 | 4 | 1 | 0 | 0 | 0 | 0 | 3 | 6 |
| Weight | 1 | 3 | 1 | 3 | 1 | 3 | 1 | 3 | 1 | 3 | 1 | 3 | — |
| Product | 0 | 18 | 1 | 12 | 1 | 12 | 1 | 0 | 0 | 0 | 0 | 9 | ? |
Step 2 — Sum the products
0 + 18 + 1 + 12 + 1 + 12 + 1 + 0 + 0 + 0 + 0 + 9 = 54
Step 3 — Check digit = (10 − sum mod 10) mod 10
(10 − (54 % 10)) % 10 = (10 − 4) % 10 = 6
Last digit of GLN is 6 — valid GLN
// glnCheckDigit.js — validate a GLN check digit function validateGln(raw) { const digits = raw.replace(/[\s-]/g, ''); if (!/^\d{13}$/.test(digits)) return false; let sum = 0; for (let i = 0; i < 12; i++) { const weight = i % 2 === 0 ? 1 : 3; sum += parseInt(digits[i], 10) * weight; } const checkDigit = (10 - (sum % 10)) % 10; return checkDigit === parseInt(digits[12], 10); } console.log(validateGln('0614141000036')); // true ✓ console.log(validateGln('0614141000037')); // false ✗ bad check digit
4. Why GLN validation matters
EDI and electronic messaging
GLNs are mandatory in EDI messages (EDIFACT, X12, GS1 XML). An invalid GLN in a purchase order or invoice causes message rejection, delays shipments, and triggers manual exception handling. Validating GLNs before transmission prevents these failures.
Supply chain and logistics
Warehouse management systems (WMS), transport management systems (TMS), and order management systems all use GLNs to route goods. A corrupted GLN can send a shipment to the wrong warehouse or create phantom inventory records.
GS1-128 barcodes and pallet labels
GS1-128 labels on pallets encode GLNs using Application Identifier (AI) 410–415 to identify ship-to, ship-from, and bill-to locations. A bad check digit causes scan failures at receiving docks, delaying goods receipt and putaway.
5. The production-ready solution
The IsValid GLN API validates the format (exactly 13 digits), computes the GS1 check digit, and returns the GS1 prefix with the associated member organisation country.
Full parameter reference and response schema: GLN Validation API docs →
6. Node.js code example
import { createClient } from '@isvalid-dev/sdk'; const iv = createClient({ apiKey: process.env.ISVALID_API_KEY }); // ── Example usage ──────────────────────────────────────────────────────────── const result = await iv.gln('0614141000036'); if (!result.valid) { console.log('Invalid GLN'); } else { console.log('Prefix:', result.prefix); // → '061' console.log('Country:', result.prefixCountry); // → 'United States' console.log('Check digit:', result.checkDigit); // → '6' }
In an EDI partner onboarding flow:
// Validate GLNs before storing trading partner locations async function onboardPartnerLocations(locations) { const results = []; for (const loc of locations) { if (!loc.gln) { results.push({ ...loc, glnStatus: 'missing' }); continue; } const check = await validateGln(loc.gln); if (!check.valid) { results.push({ ...loc, glnStatus: 'invalid' }); continue; } results.push({ ...loc, gln: loc.gln.replace(/[\s-]/g, ''), // store normalised glnPrefix: check.prefix, glnCountry: check.prefixCountry, glnStatus: 'valid', }); } return results; }
0614141000036) and parsing it as a number would strip the leading zero.7. cURL example
Validate a GLN:
curl -H "Authorization: Bearer YOUR_API_KEY" \ "https://api.isvalid.dev/v0/gln?value=0614141000036"
Invalid GLN (bad check digit):
curl -H "Authorization: Bearer YOUR_API_KEY" \ "https://api.isvalid.dev/v0/gln?value=0614141000037"
8. Understanding the response
Valid GLN:
{ "valid": true, "prefix": "061", "prefixCountry": "United States", "checkDigit": "6" }
Invalid GLN:
{ "valid": false }
| Field | Type | Description |
|---|---|---|
| valid | boolean | Exactly 13 digits, all numeric, GS1 check digit passes |
| prefix | string | 2 or 3-digit GS1 prefix identifying the issuing member organisation |
| prefixCountry | string | Country or organisation associated with this GS1 prefix |
| checkDigit | string | The computed check digit (last digit of the GLN) |
9. Edge cases
GLN-13 vs GTIN-13 (EAN)
GLN and EAN-13 (GTIN-13) share the same 13-digit format and the same check digit algorithm. The difference is semantic: an EAN identifies a product, a GLN identifies a location. You cannot tell them apart from the number alone — context determines which type it is. Always use the correct API endpoint for the identifier type.
// Same format, different meaning const productCode = '5901234123457'; // EAN-13 → use iv.ean() const locationCode = '0614141000036'; // GLN → use iv.gln()
Prefix countries
The GS1 prefix indicates which GS1 Member Organisation issued the company prefix — not the physical location of the site identified by the GLN. A GLN with prefix 400 (Germany) can refer to a warehouse in Poland if the company registered its GS1 numbers through GS1 Germany.
Party GLN vs physical location GLN
GS1 distinguishes between a party GLN (identifying a legal entity or functional entity) and a physical location GLN (identifying a specific site or sub-site). Both are syntactically identical 13-digit numbers. The distinction is maintained in master data, not in the number format itself.
Leading zeros
GLNs frequently start with zeros — for example, US-issued GLNs often begin with 0. Never parse GLNs as integers or store them in numeric database columns. Always treat GLNs as fixed-length 13-character strings.
Summary
See also
Validate GLNs instantly
Free tier includes 100 API calls per day. No credit card required. GS1 check digit validation with prefix lookup.