Created
April 12, 2018 11:45
-
-
Save barisesen/a972480b929e59e5b09a8e9408430001 to your computer and use it in GitHub Desktop.
Vergi kimlik 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 | |
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