Skip to content

Instantly share code, notes, and snippets.

@tuupola
Created September 3, 2009 14:13
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuupola/180321 to your computer and use it in GitHub Desktop.
Save tuupola/180321 to your computer and use it in GitHub Desktop.
Validate Estonian national identification number (isikukood).
/*
* Validate Estonian national identification code.
*
* Copyright (c) 2009 Mika Tuupola
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*/
function isikukood(kood) {
var multiplier_1 = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 1);
var multiplier_2 = new Array(3, 4, 5, 6, 7, 8, 9, 1, 2, 3);
var control = kood.charAt(10);
var retval = false;
var mod = 0;
var total = 0;
/* Do first run. */
for (i=0; i < 10; i++) {
total += kood.charAt(i) * multiplier_1[i];
}
mod = total % 11;
/* If modulus is ten we need second run. */
total = 0;
if (10 == mod) {
for (i=0; i < 10; i++) {
total += kood.charAt(i) * multiplier_2[i];
}
mod = total % 11;
/* If modulus is still ten revert to 0. */
if (10 == mod) {
mod = 0;
}
}
return control == mod;
}
@abilogos
Copy link

Hi tuupola i have ported this gist in php. in This address:
php version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment