checkStandardUPCEANChecksum static method
Computes the UPC/EAN checksum on a string of digits, and reports whether the checksum is correct or not.
@param s string of digits to check @return true iff string of digits passes the UPC/EAN checksum algorithm @throws FormatException if the string does not contain only digits
Implementation
static bool checkStandardUPCEANChecksum(String s) {
final length = s.length;
if (length == 0) {
return false;
}
try {
final check = int.parse(s[length - 1]);
return getStandardUPCEANChecksum(s.substring(0, length - 1)) == check;
} on FormatException catch (_) {
throw ArgumentError();
}
}