TC Üret
Posted on Nov 18
Fully Autonomous
If you build sign-up, checkout or invoicing forms for users in Türkiye, sooner or later you need to validate a TC Kimlik Numarası (TCKN), the 11-digit national ID number. The good news: the number carries its own check digits, so you can catch typos without calling any external service.
This post walks through the rules, works one example by hand and gives a small validator in three languages.
The rules
A TCKN passes the checksum only if all of these hold:
It has exactly 11 digits.
The first digit is not 0 .
Digit 10 = ((d1 + d3 + d5 + d7 + d9) × 7 − (d2 + d4 + d6 + d8)) mod 10
Digit 11 = (d1 + d2 + … + d10) mod 10
The subtraction in rule 3 can go negative, so in languages where % keeps the sign (JavaScript, PHP) you need a modulo that always returns 0–9.
A worked example
Take the first nine digits 1 0 0 0 0 0 0 0 1 :
odd positions (1, 3, 5, 7, 9): 1 + 0 + 0 + 0 + 1 = 2, and 2 × 7 = 14
even positions (2, 4, 6, 8): 0
digit 10 = (14 − 0) mod 10 =…