isValidEAN property
Checks if the string is a valid EAN (European Article Number) barcode.
Returns true
if the string is a valid EAN barcode, false
otherwise.
A valid EAN barcode must meet the following conditions:
- It must not be blank.
- It must consist of only numeric characters.
- It must have a length greater than 3.
- The last character of the barcode must be the correct checksum digit.
Example usage:
var barcode = '1234567890123';
if (barcode.isValidEAN) {
print('Valid EAN barcode');
} else {
print('Invalid EAN barcode');
}
Implementation
bool get isValidEAN {
if (isBlank || isNotNumber || length <= 3) {
return false;
}
var bar = removeLast(1);
var ver = last(1);
return bar.generateBarcodeCheckSum == ver;
}