Last active
December 11, 2015 11:08
-
-
Save alixaxel/4591689 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function isVATIN($vatin) | |
{ | |
if (preg_match('~^[125689][0-9]{8}$~', $vatin) > 0) | |
{ | |
$vatin = str_split($vatin); | |
foreach (array_slice($vatin, 0, -1) as $key => $value) | |
{ | |
$vatin[$key] *= (9 - $key); | |
} | |
if (($checksum = 11 - (array_sum(array_slice($vatin, 0, -1)) % 11)) >= 10) | |
{ | |
$checksum = 0; | |
} | |
return (strcmp($checksum, array_pop($vatin)) === 0); | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
O primeiro dígito (dígito inicial, aquele que está mais à esquerda) do NIF tem os seguintes interpretações:
O nono e último dígito é o dígito de controlo. É calculado utilizando o algoritmo módulo 11.