Daily Archives: November 20, 2008

Dutch social security number check

For a Dutch customer I currently work for, I dealed with an incorrect social security number check (in Dutch: elfproef voor BSN’s/burgerservicenummers). After checking out the Internet for the correct definition of Dutch social security numbers (e.g. Burgerservicenummer – Wikipedia), I created the next check in C#:

string cleanBsnNr = bsnNr.Trim().Replace(".", "");

// A BSN consists of 9 characters ...
if(cleanBsnNr.Length != 9) return false;

// ... all being numeric and not resulting in a 0 when converted to a number ...
long l;
if(!long.TryParse(cleanBsnNr, out l)) return false;
else if(l == 0) return false;

// ... the number must be validatable to the so-called 11-proof ...
long total = 0;
for(int i = 1; i <= 9; i++)
{
    // 11-proof voor BSN's: (9*A + 8*B + 7*C + 6*D + 5*E + 4*F + 3*G + 2*H + (-1*I)) % 11 == 0
    int number = Convert.ToInt32(cleanBsnNr[i - 1].ToString());
    int multiplier = 10 - i;
    if(i == 9) multiplier = -1 * multiplier;

    total += number * multiplier;
}

// ... not result in a 0 when dividing by 11 ...
if(total == 0) return false;

// ... and not have a modulo when dividing by 11.
return total % 11 == 0;

Good luck when you should build one for yourself. Checking your own built check can be done using this website with generated BSN’s (or your own, of course) by Menno Wilmans.