If you want to validate a European Union VAT number then an easy way is to use this php code from griffinko on codecanyon marketplace.
With this script you can submit a EU vat number including spaces and you are returned details of the company and address plus more.
EU VAT Number Validation is a simple PHP class which allows you to online validate VAT number of companies registered in European Union.
You can easily integrate validation into your existing project.
Supported countries: 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
You can use this class in your projects when you need to check if some VAT number is correct or not. For example you have B2B project and your customers must provide VAT number of their companies read the full info here. With this class it is very simple to validate VAT numbers and avoid future problems with incorrect data.