isValidMod10 static method

bool isValidMod10(
  1. String code
)

Whether the last digit of code is its correct GS1 mod-10 check digit.

Works for any length of 2 or more digits: GTIN-8, GTIN-12, GTIN-13, GTIN-14, SSCC (18) and GSIN (17).

Implementation

static bool isValidMod10(String code) {
  if (code.length < 2 || !_digits.hasMatch(code)) return false;
  return compute(code.substring(0, code.length - 1)) == code.codeUnitAt(code.length - 1) - 0x30;
}