Business::Barcode::EAN13 - Perform simple validation of an EAN-13 barcode


  use Business::Barcode::EAN13 qw/valid_barcode check_digit issuer_ccode best_barcode/;

  my $is_valid     = valid_barcode("5023965006028");
  my $check_digit  = check_digit("502396500602"); 
  my $country_code = issuer_ccode("5023965006028");
  my $best_code    = best_barcode(\@barcodes, \@prefs);


These subroutines will tell you whether or not an EAN-13 barcode is self-consistent: i.e. whether or not it checksums correctly. If provided with the 12 digit stem of a barcode it will also return the correct check digit.

We can also return the country in which the manufacturer's identifcation code was registered, and a method for picking a "most preferred" barcode from a list, given a preferred country list.



my $check_digit = check_digit("502396500602"); # 8

Given the first 12 digits of a barcode, this will tell you what the last digit should be. This will return undef if the barcode stem is not properly formed.


my $is_valid = valid_barcode("5023965006028");

Tell whether or not the given barcode is valid. This obviously does not check if it a real barcode; only if it is of correct length, and has a valid check-digit.


my $country_code = issuer_ccode("5023965006028"); # "uk"

Returns the ISO 2 digit country code (you could use Locale::Country, or equivalent, to convert to the country name, if required) of the barcode issuer. (Note: This is not necessarily the same as the country of manufacture of the goods).

This does not test the validity of the barcode.


my $best_barcode = best_barcode(\@list_of_barcodes, \@optional_prefs);

Given an arrayref of barcodes, this will return the "most preferred" barcode from the list.

If you don't pass any preferences, this will be the first valid barcode in the list. With a list of "preferred prefixes", this will return the best match from your list in order of preference of your prefix. A prefix can either be a numeric barcode stem, or a 2 letter country code, which will be expanded into the list of current barcode stems available to that country.

e.g. if you have a list of 10 barcodes for the same product internationally, and would prefer the UK barcode if it exists, otherwise the Irish one, otherwise any valid barcode, you would call:

  my $best_barcode = best_barcode(\@barcodes, ["uk", "ie"]);

If there are no valid barcodes in your list this will return the first barcode which would be valid if it was zero-padded, or null if none meet this final criterion.


When zero-filling the barcodes in "best_barcode" we should re-apply the preferences again, rather than just taking the first valid barcode.


Allow other barcode families than EAN-13


Colm Dougan, Tony Bowden and Jan Willamowius (


This program may be distributed under the same license as Perl itself.