controle btw nummer
Ik probeer tegevrees een formulier te maken waarbij het opgegeven btw-nummer gecontroleerd wordt op volgende parameters schrijfwijze
heb dit geprobeerd maar niet echt succesvol
?>
heb dit geprobeerd maar niet echt succesvol
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
* controle btw nummer
* controle op formaat en landcode
*controle belgische nummers
*invoercontrole op punt na
* controle op belgische landcode (KAN DIT INDIEN OOK ANDER LANDODES WORDEN INGEGEVEN?)
* controle op aantal nummers 9 of 10 indien eerste 0 is
*uitkomst zou boolion zijn
*/
function isBTW($btwingave)
{
$btwingave = trim($btwingave);
$btwingave = str_replace('.', '', $btwingave);
$ = array();
//eerste controle
if (!preg_match('/^([a-z]{2})[ ]*(.+)$/is', $btwingave, $controleformaat))
{
return false;
}
$controleformaat[1] = strtoupper($controleformaat[1]);
$landcodes = array(
'AT' => 'U[0-9]{8}',
'BE' => '0[0-9]{9}',
'BG' => '[0-9]{9,10}',
'CY' => '[0-9]{8}[A-Za-z]',
'CZ' => '[0-9]{8,10}',
'DE' => '[0-9]{9}',
'DK' => '[0-9]{2} ?[0-9]{2} ?[0-9]{2} ?[0-9]{2}',
'EE' => '[0-9]{9}',
'EL' => '[0-9]{9}',
'ES' => '([A-Za-z0-9][0-9]{7}[A-Za-z0-9])',
'FI' => '[0-9]{8}',
'FR' => '[A-Za-z0-9]{2} ?[0-9]{9}',
'GB' => '([0-9]{3} ?[0-9]{4} ?[0-9]{2}|[0-9]{3} ?[0-9]{4} ?[0-9]{2} ?[0-9]{3}|GD[0-9]{3}|HA[0-9]{3})',
'HU' => '[0-8]{8}',
'IE' => '[0-9][A-Za-z0-9+*][0-9]{5}[A-Za-z]',
'IT' => '[0-9]{11}',
'LT' => '([0-9]{9}|[0-9]{12})',
'LU' => '[0-9]{8}',
'LV' => '[0-9]{11}',
'MT' => '[0-9]{8}',
'NL' => '[0-9]{9}B[0-9]{2}',
'PL' => '[0-9]{10}',
'PT' => '[0-9]{9}',
'RO' => '[0-9]{2,10}',
'SE' => '[0-9]{12}',
'SI' => '[0-9]{8}',
'SK' => '[0-9]{10}',
);
if (!isset($landcodes[$controleformaat[1]]) || !preg_match('/^([a-z]{2})[ ]*'.$landcodes[$controleformaat[1]].'$/is', $btwingave))
{
return false;
}
return true;
}
//TWEEDE CONTROLE ALLEEN OP BELGIE
function $belgischbtwnummer($btwingave)
{
$resultaat1 = str_replace(array(' ', '.'),'',($btwingave));
if(preg_match('#^BE0?[0-9]{9}$#i', $resultaat1))
{
$resultaat2 = str_ireplace('BE','', $resultaat1);
$controle = 97 - (floor($iVatnr / 100) % 97) ==$resultaat2 % 100;
}
else
{
$controle = false;
}
return $controle;
}
?>
/**
* controle btw nummer
* controle op formaat en landcode
*controle belgische nummers
*invoercontrole op punt na
* controle op belgische landcode (KAN DIT INDIEN OOK ANDER LANDODES WORDEN INGEGEVEN?)
* controle op aantal nummers 9 of 10 indien eerste 0 is
*uitkomst zou boolion zijn
*/
function isBTW($btwingave)
{
$btwingave = trim($btwingave);
$btwingave = str_replace('.', '', $btwingave);
$ = array();
//eerste controle
if (!preg_match('/^([a-z]{2})[ ]*(.+)$/is', $btwingave, $controleformaat))
{
return false;
}
$controleformaat[1] = strtoupper($controleformaat[1]);
$landcodes = array(
'AT' => 'U[0-9]{8}',
'BE' => '0[0-9]{9}',
'BG' => '[0-9]{9,10}',
'CY' => '[0-9]{8}[A-Za-z]',
'CZ' => '[0-9]{8,10}',
'DE' => '[0-9]{9}',
'DK' => '[0-9]{2} ?[0-9]{2} ?[0-9]{2} ?[0-9]{2}',
'EE' => '[0-9]{9}',
'EL' => '[0-9]{9}',
'ES' => '([A-Za-z0-9][0-9]{7}[A-Za-z0-9])',
'FI' => '[0-9]{8}',
'FR' => '[A-Za-z0-9]{2} ?[0-9]{9}',
'GB' => '([0-9]{3} ?[0-9]{4} ?[0-9]{2}|[0-9]{3} ?[0-9]{4} ?[0-9]{2} ?[0-9]{3}|GD[0-9]{3}|HA[0-9]{3})',
'HU' => '[0-8]{8}',
'IE' => '[0-9][A-Za-z0-9+*][0-9]{5}[A-Za-z]',
'IT' => '[0-9]{11}',
'LT' => '([0-9]{9}|[0-9]{12})',
'LU' => '[0-9]{8}',
'LV' => '[0-9]{11}',
'MT' => '[0-9]{8}',
'NL' => '[0-9]{9}B[0-9]{2}',
'PL' => '[0-9]{10}',
'PT' => '[0-9]{9}',
'RO' => '[0-9]{2,10}',
'SE' => '[0-9]{12}',
'SI' => '[0-9]{8}',
'SK' => '[0-9]{10}',
);
if (!isset($landcodes[$controleformaat[1]]) || !preg_match('/^([a-z]{2})[ ]*'.$landcodes[$controleformaat[1]].'$/is', $btwingave))
{
return false;
}
return true;
}
//TWEEDE CONTROLE ALLEEN OP BELGIE
function $belgischbtwnummer($btwingave)
{
$resultaat1 = str_replace(array(' ', '.'),'',($btwingave));
if(preg_match('#^BE0?[0-9]{9}$#i', $resultaat1))
{
$resultaat2 = str_ireplace('BE','', $resultaat1);
$controle = 97 - (floor($iVatnr / 100) % 97) ==$resultaat2 % 100;
}
else
{
$controle = false;
}
return $controle;
}
?>
?>
Roep je de functie aan?
dacht het wel maar denk dat probleem zit in het ontbreken van controles op juist heid andere landen maar ben hier echt niet goed in :-(
Hoe roep je de functie nu aan?
Is het niet beter om het te controleren via VIES?
Dat is de database van de Europese Commissie waarin dus echt aangegeven wordt of het BTW nummer geldig is.
Nu controleer je het enkel op het formaat, terwijl het nummer dan niet per definitie geldig hoeft te zijn.
Dit doe je op http://ec.europa.eu/taxation_customs/vies/?locale=nl
Voor het automatisch te doen, kijk eens naar: http://stackoverflow.com/questions/9158119/vies-vat-number-validation
Dat is de database van de Europese Commissie waarin dus echt aangegeven wordt of het BTW nummer geldig is.
Nu controleer je het enkel op het formaat, terwijl het nummer dan niet per definitie geldig hoeft te zijn.
Dit doe je op http://ec.europa.eu/taxation_customs/vies/?locale=nl
Voor het automatisch te doen, kijk eens naar: http://stackoverflow.com/questions/9158119/vies-vat-number-validation




