4

I'm tasked with validating GTIN-14, GTIN-13, GTIN-12, GTIN-8 and UPC-E barcodes. I have seen a few functions here and there, however I'm unclear on how to validate the code without knowing ahead of time which standard is in use.

I assume this must be possible, but I'm at a loss as to where I should begin.

Shog9
  • 156,901
  • 35
  • 231
  • 235
Sunil Kumbhar
  • 175
  • 1
  • 5
  • Is the intent of the question to actually scan barcodes of various types and validate their content, or simply to validate a given string containing a GTIN number (of various types)? If the latter, then provided that it is a EAN/UPC that is being scanned it is always the same validation process since the GS1 numeric check digit algorithm is agnostic to the length of the GTIN as it weights the digits from right to left: https://www.gs1.org/services/how-calculate-check-digit-manually – Terry Burton Mar 21 '23 at 10:03
  • Note that values from a UPC-E must first be "un-suppressed" back to a GTIN-12 (have the zeros added back in), which scanners should do as standard: https://stackoverflow.com/a/31539006/2568535 – Terry Burton Mar 21 '23 at 10:12

1 Answers1

1

Validating the content of the barcode shouldn't be a problem. Take a look at the specification for the different GTIN-Formats. The problematic part is to check the existence of the required GS1 Symbol identifier. The commonly used libs for barcode decoding (zxing, zbar) do not give you the Symbol identifier. The only exception is zxing for Code-128. If you have to check other carrier types you will have to look into commercial decoders. Take a look at this question for more details.

Community
  • 1
  • 1
tobltobs
  • 2,782
  • 1
  • 27
  • 33