<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Sjekk av personnummer, basert på http://wapedia.mobi/no/Diskusjon:F%C3%B8dselsnummer</title>
<script type="text/javascript">
//<![CDATA[
function check_personalnumber_no( pno ) {
// Check length
if( pno.length != 11 )
return false;
// Split
day = pno.substr(0,2);
month = pno.substr(2,2);
year = pno.substr(4,2);
ind = pno.substr(6,3);
c1 = pno.substr(9,1);
c2 = pno.substr(10,1);
yearno = parseInt(year);
if( ind > 0 && ind < 500 ) {
yearno += 1900;
} else if( ind > 499 && ind < 750 && year > 55 && year < 100) {
yearno += 1800;
} else if( ind > 499 && ind < 999 && year >= 00 && year < 40) {
yearno += 2000;
} else if( ind > 899 && ind < 999 && year > 39 && year < 100) {
yearno += 1900;
} else {
return false;
}
d1 = parseInt(day.substr(0,1));
d2 = parseInt(day.substr(1,1));
m1 = parseInt(month.substr(0,1));
m2 = parseInt(month.substr(1,1));
a1 = parseInt(year.substr(0,1));
a2 = parseInt(year.substr(1,1));
i1 = parseInt(ind.substr(0,1));
i2 = parseInt(ind.substr(1,1));
i3 = parseInt(ind.substr(2,1));
// Calculate control check c1
c1calc = 11 - (((3*d1) + (7*d2) + (6*m1) + m2 + (8*a1) + (9*a2) + (4*i1) + (5*i2) + (2*i3)) % 11);
if( c1calc == 11 )
c1calc = 0;
if( c1calc == 10 )
return false;
if( c1 != c1calc )
return false;
// Calculate control check c2
c2calc = 11 - (((5*d1) + (4*d2) + (3*m1) + (2*m2) + (7*a1) + (6*a2) + (5*i1) + (4*i2) + (3*i3) + (2*c1calc)) % 11);
if( c2calc == 11 )
c2calc = 0;
if( c2calc == 10 )
return false;
if( c2 != c2calc )
return false;
return true;
}
//]]>
</script>
</head>
<body>
<form onsubmit="if( !check_personalnumber_no(this.elements['pno'].value)) alert('Det er noe feil...'); else alert('Alt er ok...'); return false">
<input type="text" name="pno" size="11" value="" />
<input type="submit" name="submit" value="Check" />
</form>
</body>
</html>