in reply to Pattern Identification

^[A-Z]{2}\d{9}[A-Z]{2}$ Royal Mail Track & Trace code ^\d{16}$ visa card ^\d{13}$ EAN-13 barcode

It seems you are working with a barcode scanner. All barcode scanners I've seen so far can be configured to add prefixes or suffixes to indicate the type of barcode scanned. This could be used here. By enabling a barcode type prefix, you could better check for what has been scanned: A 13-digit number is just junk unless it is prefixed with the "this is a EAN barcode" prefix, in that case, it is really an EAN 13 barcode. If you see instead e.g. a Codabar prefix and a 13 digit number, whatever you scanned was not a EAN-13.

This works extremely well, I know this feature is used in blood banks to prevent misreadings of wrong labels.

The first manual I found (https://www.prosoft.ru/cms/f/426190.pdf) contains a long list of barcodes and identifier prefixes on page 25 (PDF page 26), one "AIM standard" ("]" + one upper case letter + one digit) and one "Datalogic Standard" (singe upper or lower case letter), and it suggests that you can reconfigure the codes.

The list shows several different identifiers for EAN, as you can have EANs in 8 or 13 digits, and they can have two different, mutual exlusive add-ons, resulting in six identifiers.

Another thing to consider is to configure the (USB) barcode scanner not to emulate a keyboard, but instead to present itself as a serial device. This prevents manual "scanning" by typing in data via the keyboard. The application that uses the scanner needs to be changed a little bit, but it avoids the largest source of errors: The human using the computer. As a nice side effect, it also avoids problems with Caps Lock, Num Lock, and non-US keyboard layouts.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re^2: Pattern Identification
by WhiteTraveller (Novice) on Oct 01, 2017 at 10:30 UTC

    Hi Alexander,

    You are quite correct! I have already configured the addition of the code prefix -- it helps to give additional information to help discriminate and distinguish between the various options. Thank you for the tip about the keyboard scanner, it may be useful.