Skip to content

Commit a5eec52

Browse files
committed
Adding the same length check and exception as for PZN.
1 parent 1080baa commit a5eec52

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

barcode/ean.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ def __init__(self, ean, writer=None):
4141
ean = ean[:self.digits]
4242
if not ean.isdigit():
4343
raise IllegalCharacterError('EAN code can only contain numbers.')
44+
if len(ean) != self.digits:
45+
raise NumberOfDigitsError('EAN must have {0} digits, not '
46+
'{1}.'.format(self.digits, len(ean)))
4447
self.ean = ean
4548
self.ean = '{0}{1}'.format(ean, self.calculate_checksum())
4649
self.writer = writer or Barcode.default_writer()

0 commit comments

Comments
 (0)