Created
December 9, 2013 16:46
-
-
Save tdoumas/7875586 to your computer and use it in GitHub Desktop.
Αλγόριθμος ορθότητας AMKA
Greek Social Security Number (AMKA)
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
// Greek Social Security Number Validation (AMKA) | |
// Αλγόριθμος ορθότητας ΑΜΚΑ | |
function validateAMKA(amka) { | |
if (!amka.match(/^\d{11}$/) || amka == '00000000000') | |
return false; | |
var iSum = 0; | |
for (var i = 1; i <= amka.length; i++) { | |
var iDigit = parseInt(amka.charAt(i - 1), 10); | |
if (i % 2 === 0) { | |
iDigit *= 2; | |
if (iDigit > 9) { | |
iDigit -= 9; | |
} | |
} | |
iSum += iDigit; | |
} | |
return (iSum % 10 === 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment