I've found that barcode scans are often incorrect during my tests, Ive mostly been testing UPC's around the house, so I dont know what format they are in.
its tough to give instructions on how to duplicate, but It seems to happen most often when there is a glare on the barcode that reduces visibility or alters the appearance.
My understanding of barcode scanners is that they will use a checksum to validate a scan before it is accepted. this does not seem to be happening, so that's why I'm marking it as a bug. the scanner appears to be very sensitive as compared to, say, the shopify mobile barcode scanner, which by the length of time it takes to scan something and the scanner app they implement has some redundant checking going on.
my current workaround is to build in my own checksum verification function to make sure the scanned barcode is correct before inserting it into the form. see below.
function isValidUPCA(barcode) {
if (barcode.length !== 12) {
return false;
}
let checksum = 0;
for (let i = 0; i < 11; i++) {
let digit = parseInt(barcode[i]);
if (i % 2 === 0) {
checksum += digit * 3;
} else {
checksum += digit;
}
}
let calculatedChecksum = (10 - (checksum % 10)) % 10;
let scannedChecksum = parseInt(barcode[11]);
return calculatedChecksum === scannedChecksum;
}