Codice PHP:
/**
* verify_eu_vat()
*
* True European VAT validation.
*
* @param mixed $vat_number
* @return boolean Success
*/
function verify_eu_vat($vat_number)
{
// Check for invalid characters, split the VAT number into country VAT ID
if(!ereg('([A-Z]{2})([0-9A-Z]*)', $vat_number, $regs))
{
return false;
}
$country_id = $regs[1];
$vat_id = $regs[2];
$url = "http://ec.europa.eu/taxation_customs/vies/cgi-bin/viesquer?Lang=EN&MS=$country_id&ISO=$country_id&VAT=$vat_id";
$reply = @file_get_contents($url);
return strpos($reply, 'Yes, valid VAT number') ? true : false;
}
Segnalibri