Created
June 24, 2020 12:07
-
-
Save teyfix/a6f56244db05ea54205b94bb89588c2f to your computer and use it in GitHub Desktop.
tc kimlik numarası doğrulama
This file contains hidden or 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
// Kimliğin ilk 9 rakamı için d, kontrol basamakları için c kullanırsak : | |
// Tc No = d1 d2 d3 d4 d5 d6 d7 d8 d9 c1 c2 | |
// c1 = ( (d1 + d3 + d5 + d7 + d9) * 7 - (d2 + d4 + d6 + d8) ) mod10 | |
// c2 = ( d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8 + d9 + c1 ) mod10 | |
class TC { | |
static final RegExp regExp = RegExp(r"^\d{11}$"); | |
static bool validate(String tc) { | |
if (regExp.hasMatch(tc)) { | |
int sum = 0; | |
int sumOdd = 0; | |
int sumEven = 0; | |
int c1, c2; | |
for (int i = 0; i < tc.length; i++) { | |
final e = int.parse(tc[i]); | |
if (i == 9) { | |
c1 = e; | |
} else if (i == 10) { | |
c2 = e; | |
} else { | |
sum += e; | |
if (i % 2 == 0) { | |
sumEven += e; | |
} else { | |
sumOdd += e; | |
} | |
} | |
} | |
return c1 == ((sumEven * 7 - sumOdd) % 10) && c2 == ((sum + c1) % 10); | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment