Google Sheets GTIN Check Digit Validator – Simple App Script for Product Data Accuracy

If you manage product feeds for Google Merchant Center, Amazon, or other marketplaces, you’ll know that valid GTINs (Global Trade Item Numbers) are essential for product approval and visibility.
A single incorrect digit can cause disapprovals, lower performance, and lost sales.

To make it easier to validate GTINs directly inside Google Sheets, I’ve written a small Google Apps Script that checks GTINs and calculates their check digit using the standard GTIN algorithm.


What Does This Script Do?

The script:

  1. Reads GTINs from column A of your Google Sheet.
  2. Validates them by calculating the correct check digit using the modulus 10 (Luhn) algorithm.
  3. Outputs the correct check digit into column B, so you can quickly spot mismatches or errors.
function checkDigit() {
  ss = SpreadsheetApp.getActiveSpreadsheet();
  sheets = ss.getSheets();
  s = sheets[0];
  var r = s.getRange("A:A");
  var v = r.getValues();
  
  for (var i = 0; i < v.length; i++) {
    var hold = v[i][0].toString();
    if (hold && hold !== "null") {
      var array = hold.split("").reverse();
      var total = 0;
      var j = 1;
      
      array.forEach((number) => {
        number = parseInt(number, 10);
        if (j % 2 === 0) {
          total += number;
        } else {
          total += number * 3;
        }
        j++;
      });
      
      s.getRange(i + 1, 2)
       .setValue(Math.ceil(total / 10) * 10 - total);
    }
  }
}

How to Use It

  1. Open your Google Sheet containing GTINs in column A.
  2. Go to Extensions → Apps Script and paste in the code above.
  3. Save the script, then run checkDigit() from the Script Editor.
  4. The calculated check digit will appear in column B next to each GTIN.

Why This Helps

  • Quick validation without needing to export to another tool.
  • Catch invalid GTINs before uploading product feeds.
  • Reduce feed errors in Google Merchant Center, Amazon, and other platforms.

This is a lightweight way to add an extra layer of QA to your product data workflow right inside Google Sheets.