Created
January 18, 2019 08:34
-
-
Save barisesen/ea1931b3a15088f0fa9f48ee4e995852 to your computer and use it in GitHub Desktop.
Tc kimlik numarası doğrulama - javascript
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
function verify(tcno) { | |
if (!tcno.match(/^[1-9]{1}[0-9]{9}[0,2,4,6,8]{1}$/)) { | |
return false; | |
} | |
tcno = tcno.split('').map(Number); | |
var odd = tcno[0] + tcno[2] + tcno[4] + tcno[6] + tcno[8]; | |
var even = tcno[1] + tcno[3] + tcno[5] + tcno[7]; | |
var digit10 = (odd * 7 - even) % 10; | |
var total = (odd + even + tcno[9]) % 10; | |
return !(digit10 !== tcno[9] || total !== tcno[10]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment