DocsValidators

gtin validator

GS1 GTIN-8/12/13/14 with trailing-digit checksum.

Format

Strips whitespace, then matches 8, 12, 13, or 14 digits and verifies the GS1 mod-10 trailing-digit checksum.

Examples

  • 7613034626844 (GTIN-13, EAN)
  • 00012345600012 (GTIN-14, SSCC-style)
  • 0123456789012 (GTIN-13 with leading zero — keep as string!)

Implementation

Faithful summary of lib/validators.ts. Validators are pure functions and run identically in the worker, the Workbench, and the MCP server.

function validGtin(value) {
  const v = value.replace(/\s+/g, '')
  if (!/^\d{8}$|^\d{12,14}$/.test(v)) {
    return fail('gtin_format', 'expected 8/12/13/14 digits')
  }
  const digits = v.split('').map(Number)
  const check = digits.pop()
  const sum = digits.reverse().reduce(
    (acc, d, i) => acc + d * (i % 2 === 0 ? 3 : 1), 0,
  )
  const want = (10 - (sum % 10)) % 10
  return check === want ? OK : fail('gtin_checksum', 'bad GTIN checksum')
}

Use in a template

Validators attach to a field on a custom template. The cascade runs them after mapping but before commit; failures surface in the per-row validation report.

fields:
  - column: gtin
    type: string
    validators:
      - type: gtin

Common gotchas

  • Leading zeros are significant. Always send GTINs as strings — Excel/JSON parsers that coerce to number will silently drop them and fail the format check.
  • GTIN-11 is intentionally not accepted (not a GS1 form). GTIN-9, 10 are also rejected.
  • The reserved Restricted Circulation range (RCN) passes if the checksum is valid; we do not flag GS1 prefix semantics.

Related templates

  • Drug formularydrug_formulary_v1

    ATC/GTIN-coded drug catalog. Emits FHIR Medication.

    Fields: gtin

  • Supplier inventorysupplier_inventory_v1

    Supplier catalogue with GTIN/IBAN/GLN.

    Fields: gtin

  • Productsproducts_v1

    Product catalog: SKU, GTIN, price, category, weight, stock flag.

    Fields: gtin

Pricing

Validators run on every committed row

Schema-only mode (headers + ≤3 sample rows) is free and unlimited; full-data commits are metered. See plans →

gtin validator — AdaptivMapr