View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Bernard Nauwelaerts > Business-Tax-VAT-Validation-1.01 > Business::Tax::VAT::Validation



Annotate this POD


New  1
Open  0
View/Report Bugs
Module Version: 1.01   Source   Latest Release: Business-Tax-VAT-Validation-1.11


Business::Tax::VAT::Validation - A class for european VAT numbers validation.


  use Business::Tax::VAT::Validation;
  my $hvatn=Business::Tax::VAT::Validation->new();
  # Check number
  if ($hvatn->check($VAT, [$member_state])){
        print "OK\n";
  } else {
        print $hvatn->get_last_error;


This class provides an easy api to check european VAT numbers' syntax, and if they has been registered by the competent authorities.

It asks the EU database (VIES) for this, using its SOAP interface methods.


new Class constructor.
    If your system is located behind a proxy :
    $hvatn=Business::Tax::VAT::Validation->new(-proxy => ['http', '']);
    Note : See LWP::UserAgent for proxy options.


member_states Returns all member states 2-digit codes as array
regular_expressions - Returns a hash list containing one regular expression for each country

If you want to test a VAT number format ouside this module, e.g. embedded as javascript in a web form.



    AT      =>  'U[0-9]{8}',
    SK        =>  '[0-9]{10}',


check - Checks if a VAT number exists in the VIES database
    $ok=$hvatn->check($vatNumber, [$countryCode]);

You may either provide the VAT number under its complete form (e.g. BE-123456789, BE123456789) or specify the VAT and MSC (vatNumber and countryCode) individually.

Valid MS values are :

 AT, BE, BG, CY, CZ, DE, DK, EE, EL, ES,
 FI, FR, GB, HU, IE, IT, LU, LT, LV, MT,
local_check - Checks if a VAT number format is valid This method is based on regexps only and DOES NOT ask the VIES database
    $ok=$hvatn->local_check($VAT, [$member_state]);
informations - Returns informations related to the last validated VAT number
get_last_error_code - Returns the last recorded error code
get_last_error - Returns the last recorded error
    my $err = $hvatn->get_last_error_code();
    my $txt = $hvatn->get_last_error();

Possible errors are :

  • -1 The provided VAT number is valid.
  • 0 Unknown MS code : Internal checkup failed (Specified Member State does not exist)
  • 1 Invalid VAT number format : Internal checkup failed (bad syntax)
  • 2 This VAT number doesn't exist in EU database : distant checkup
  • 3 This VAT number contains errors : distant checkup
  • 17 Time out connecting to the database : Temporary error when the connection to the database times out
  • 18 Member Sevice Unavailable: The EU database is unable to reach the requested member's database.
  • 19 The EU database is too busy.
  • 20 Connexion to the VIES database failed.
  • 21 The VIES interface failed to parse a stream. This error occurs unpredictabely, so you should retry your validation request.
  • 257 Invalid response, please contact the author of this module. : This normally only happens if this software doesn't recognize any valid pattern into the response document: this generally means that the database interface has been modified, and you'll make the author happy by submitting the returned response !!!
  • 500 The VIES server encountered an internal server error. Error 500 : soap:Server TIMEOUT Error 500 : soap:Server MS_UNAVAILABLE

If error_code > 16, you should temporarily accept the provided number, and periodically perform new checks until response is OK or error < 17 If error_code > 256, you should temporarily accept the provided number, contact the author, and perform a new check when the software is updated.


LWP::UserAgent for the FAQs related to the VIES service.


If you find this module useful, or have any comments, suggestions or improvements, feel free to let me know.


Bernard Nauwelaerts <>


Many thanks to the following people, actively involved in the development of this software by submitting patches, bug reports, new members regexps, VIES interface changes,... (sorted by last intervention) :


GPL. Enjoy! See COPYING for further informations on the GPL.


See to known the limitations of the EU validation service.

  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
syntax highlighting: