-
-
Save ferdiunal/a8bd673da6aaebd8f92239ddac2a6194 to your computer and use it in GitHub Desktop.
PHP Vergi Numarası Doğrulama
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 | |
/** | |
* This method logically validates Turkish VAT number | |
* | |
* @param string $taxNumber | |
* @return bool | |
*/ | |
public function validateTaxNumber(string $taxNumber): bool | |
{ | |
if (strlen($taxNumber) !== 10) { | |
return false; | |
} | |
$total = 0; | |
$checkNum = null; | |
for ($i = 0; $i < 9; $i++) { | |
$tmp1 = ($taxNumber[$i] + (9 - $i)) % 10; | |
$tmp2 = ($tmp1 * (2 ** (9 - $i))) % 9; | |
if ($tmp1 !== 0 && $tmp2 === 0) { | |
$tmp2 = 9; | |
} | |
$total += $tmp2; | |
} | |
$checkNum = ($total % 10 !== 0) ? (10 - ($total % 10)) : 0; | |
return ((int)$taxNumber[9] === $checkNum) ?? false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment