Skip to content

Instantly share code, notes, and snippets.

@barisesen
Created April 12, 2018 11:45
Show Gist options
  • Save barisesen/a972480b929e59e5b09a8e9408430001 to your computer and use it in GitHub Desktop.
Save barisesen/a972480b929e59e5b09a8e9408430001 to your computer and use it in GitHub Desktop.
Vergi kimlik numarası doğrulama
<?php
namespace Libraries;
class TaxNumber
{
public static function check($tax)
{
$tax = str_replace(' ', '', trim($tax));
if (strlen($tax) != 10) {
return false;
}
$sum = 0;
for ($i=0; $i < 9; $i++) {
$val = ($tax[$i] + (9 - $i)) % 10;
$val2 = ($val * (2 ** (9 - $i))) % 9;
if ($val != 0 && $val2 == 0) {
$val2 = 9;
}
$sum += $val2;
}
$last = (10 - ($sum % 10)) % 10;
if ($last != $tax[9]) {
return false;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment