Skip to content

Instantly share code, notes, and snippets.

@emir
Last active December 26, 2023 18:40
Show Gist options
  • Save emir/e5e427243c28fdeb79158a26d566ce79 to your computer and use it in GitHub Desktop.
Save emir/e5e427243c28fdeb79158a26d566ce79 to your computer and use it in GitHub Desktop.
PHP Vergi Numarası Doğrulama
<?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;
}
@bilalyilmax
Copy link

Eline sağlık çok iyi yapmışsın, işimi kolaylaştırdın. Yoksa bende js bulmuştum ordan evircektim

@ibrahimsayar
Copy link

eline sağlık ya internette harbiden yok

@mehmetkurt
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment