note 94889 deleted from function.preg-match by danbrown
| From: | danbrown@php.net | Date: | Wed, 03 Aug 2011 13:09:13 +0000 |
| Subject: | note 94889 deleted from function.preg-match by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-182142@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
<?php
/**
* @param integer $vat_number VAT number to test e.g. GB123 4567 89
* @return integer -1 if country not included OR 1 if the VAT Num matches for the country OR 0 if no
match
*/
function checkVatNumber( $vat_number ) {
switch(strtoupper(substr($vat_number,0, 2))) {
case 'AT':
$regex = '/^(AT){0,1}U[0-9]{8}$/i';
break;
case 'BE':
$regex = '/^(BE){0,1}[0]{0,1}[0-9]{9}$/i';
break;
case 'BG':
$regex = '/^(BG){0,1}[0-9]{9,10}$/i';
break;
case 'CY':
$regex = '/^(CY){0,1}[0-9]{8}[A-Z]$/i';
break;
case 'CZ':
$regex = '/^(CZ){0,1}[0-9]{8,10}$/i';
break;
case 'DK':
$regex = '/^(DK){0,1}([0-9]{2}[\ ]{0,1}){3}[0-9]{2}$/i';
break;
case 'EE':
case 'DE':
case 'PT':
case 'EL':
$regex = '/^(EE|EL|DE|PT){0,1}[0-9]{9}$/i';
break;
case 'FR':
$regex = '/^(FR){0,1}[0-9A-Z]{2}[\ ]{0,1}[0-9]{9}$/i';
break;
case 'FI':
case 'HU':
case 'LU':
case 'MT':
case 'SI':
$regex = '/^(FI|HU|LU|MT|SI){0,1}[0-9]{8}$/i';
break;
case 'IE':
$regex = '/^(IE){0,1}[0-9][0-9A-Z\+\*][0-9]{5}[A-Z]$/i';
break;
case 'IT':
case 'LV':
$regex = '/^(IT|LV){0,1}[0-9]{11}$/i';
break;
case 'LT':
$regex = '/^(LT){0,1}([0-9]{9}|[0-9]{12})$/i';
break;
case 'NL':
$regex = '/^(NL){0,1}[0-9]{9}B[0-9]{2}$/i';
break;
case 'PL':
case 'SK':
$regex = '/^(PL|SK){0,1}[0-9]{10}$/i';
break;
case 'RO':
$regex = '/^(RO){0,1}[0-9]{2,10}$/i';
break;
case 'SE':
$regex = '/^(SE){0,1}[0-9]{12}$/i';
break;
case 'ES':
$regex = '/^(ES){0,1}([0-9A-Z][0-9]{7}[A-Z])|([A-Z][0-9]{7}[0-9A-Z])$/i';
break;
case 'GB':
$regex = '/^(GB){0,1}([1-9][0-9]{2}[\ ]{0,1}[0-9]{4}[\
]{0,1}[0-9]{2})|([1-9][0-9]{2}[\ ]{0,1}[0-9]{4}[\ ]{0,1}[0-9]{2}[\
]{0,1}[0-9]{3})|((GD|HA)[0-9]{3})$/i';
break;
default:
return -1;
break;
}
return preg_match($regex, $vat_number);
}
?>