Created
September 3, 2009 14:13
-
-
Save tuupola/180321 to your computer and use it in GitHub Desktop.
Validate Estonian national identification number (isikukood).
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
/* | |
* 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can find information only in Estonian. Below is a quick translation of the Wikipedia page.
-cut-
The control number is calculated using mod 11 using either multiplier set 1 or 2.
Multiplier set 1: 1 2 3 4 5 6 7 8 9 1
Multiplier set 2: 3 4 5 6 7 8 9 1 2 3
Take the first 10 numbers of the id code and multiply them with a number from set 1. Divide the sum of multiplying results with 11. If remainder is not 10 this is the control number.
If however reminder is 10 take the first 10 numbers of the id code and multiply them with a number from set 2. Divide the sum of multiplying results with 11. If remainder is not 10 this is the control number. If however reminder is 10 control number will be 0.
-cut-
You could also check dknight/Isikukood-js.