public static bool isValidBarcode(string barcodeWithPrefix) { string prefix = barcodeWithPrefix.Substring(0, Settings.itemBarcodeMandatoryPrefix.Length); string hex = barcodeWithPrefix.Substring(Settings.itemBarcodeMandatoryPrefix.Length); if (prefix.ToUpper() != Settings.itemBarcodeMandatoryPrefix.ToUpper()) { Tools.hasMessage(String.Format("{0} is not a valid prefix", barcodeWithPrefix.Substring(0, Settings.itemBarcodeMandatoryPrefix.Length))); return(false); } if (hex.Length != Settings.itemBarcodeLength) { Tools.hasMessage(String.Format("{0} is not a valid barcode: must be {1} digits", barcodeWithPrefix, Settings.itemBarcodeLength)); return(false); } if (!Tools.isHexNumber(hex)) { Tools.hasMessage(String.Format("{0} is not a valid barcode", barcodeWithPrefix)); return(false); } return(true); }