6 use Algorithm::CheckDigits;
 
   9   my ($class, $ustid) = @_;
 
  12   $ustid   =~ s{[[:space:].-]+}{}g;
 
  18   my ($class, $ustid) = @_;
 
  20   $ustid = $class->clean($ustid);
 
  22   if ($ustid =~ m{^CHE(\d{3})(\d{3})(\d{3})$}) {
 
  23     return sprintf('CHE-%s.%s.%s', $1, $2, $3);
 
  29 sub _validate_switzerland {
 
  32   return $ustid =~ m{^CHE\d{9}$} ? 1 : 0;
 
  35 sub _validate_european_union {
 
  38   # 1. Two upper-case letters with the ISO 3166-1 Alpha-2 country code (exception: Greece uses EL instead of GR)
 
  39   # 2. Up to twelve alphanumeric characters
 
  41   return 0 unless $ustid =~ m{^(?:AT|BE|BG|CY|CZ|DE|DK|EE|EL|ES|FI|FR|GB|HR|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK|SM)[[:alnum:]]{1,12}$};
 
  43   my $algo_name = "ustid_" . lc(substr($ustid, 0, 2));
 
  44   my $checker   = eval { CheckDigits($algo_name) };
 
  46   return $checker->is_valid(substr($ustid, 2)) if $checker;
 
  51   my ($class, $ustid) = @_;
 
  53   $ustid = $class->clean($ustid);
 
  55   return _validate_switzerland($ustid) if $ustid =~ m{^CHE};
 
  56   return _validate_european_union($ustid);
 
  68 SL::VATIDNr - Helper routines for dealing with VAT ID numbers
 
  69 ("Umsatzsteuer-Identifikationsnummern", "UStID-Nr" in German) and
 
  70 Switzerland's enterprise identification numbers (UIDs)
 
  74     my $is_valid = SL::VATIDNr->validate($ustid);
 
  80 =item C<clean> C<$ustid>
 
  82 Returns the number with all spaces, dashes & points removed.
 
  84 =item C<normalize> C<$ustid>
 
  86 Normalizes the given number to the format usually used in the country
 
  87 given by the country code at the start of the number
 
  88 (e.g. C<CHE-123.456.789> for a Swiss UID or DE123456789 for a German
 
  91 =item C<validate> C<$ustid>
 
  93 Returns whether or not a number is valid. Depending on the country
 
  94 code at the start several tests are done including check digit
 
  97 The number in question is first run through the L</clean> function and
 
  98 may therefore contain certain ignored characters.
 
 108 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>