PHP: check if ‘rijksregisternummer’ is valid.

I couldn’t find a decent PHP function to check the validation of the so called “rijksregisternummer” in Belgium (or “numéro de registre national” in French). I did however find a well written C# function by Tjeuten, so I decided to translate his C# function into PHP.

This is the result (html form checker incl):

Rijksregisternummer:
Gender:
unknown
female
male

997){
$counterOK = false;
} else if ($counterPart % 2 == 0) { //EVEN
$counterOK = true;
$gender = "F"; //FEMALE
} else {
$counterOK = true;
$gender = "M"; //MALE
}

if($givenGender != ""){
if($givenGender == $gender){
$genderOk = true;
}
} else {
$genderOk = true;
}

/* 4. RETURN GENDER OR MESSAGE */
/*******************************/

$message = "";

if (!$birthDateOK){
$message .= "Invalid birthdate;";
}
if (!$counterOK){
$message .= "Invalid counter;";
}
if (!$controlOK){
$message .= "Invalid control number;";
}
if (!$genderOk){
$message .= "Invalid gender;";
}

if ($message != "") //THERE ARE ERRORS
{
return $message;
} else {
return true;
}
}
}
}
else
{
return "isnull";
}
}

You May Also Like

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.