-
-
Save ozkanozcan/5685cb841a261fcfda4075f4809ef32b 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; | |
} | |
if ($total % 10 === 0) { | |
$checkNum = 0; | |
} else { | |
$checkNum = 10 - ($total % 10); | |
} | |
if ((int)$taxNumber[9] !== $checkNum) { | |
return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment