Skip to content

Instantly share code, notes, and snippets.

@Joaquim3
Created July 22, 2024 17:52
Show Gist options
  • Select an option

  • Save Joaquim3/74dbb4601f67978dcf6a9b99ef30e157 to your computer and use it in GitHub Desktop.

Select an option

Save Joaquim3/74dbb4601f67978dcf6a9b99ef30e157 to your computer and use it in GitHub Desktop.
PHP -> Check if National Belgian Registry Number is Correct
<?php
//------------------------------------------------------------------------
// purpose : this is used to check if a Belgian person's national registry number is correct
// params : $sNumber (11 digits) example 84102512345
// $sTmpYear (4 digits) exemple : 1984
// output : true/false
//------------------------------------------------------------------------
function fncCheckBelgianRegistryNumber($sNumber, $sTmpYear) {
$sTmpNbr = $sTmpDate = $sTDigit = "";
$sTmpNbr = $sNumber;
//11 chiffres
if (strlen($sTmpNbr)==11) {
$sTmpDate = $sTmpYear."-".substr($sTmpNbr, 2, 2)."-".substr($sTmpNbr, 4, 2);
if ($sTmpDate<="1999-12-31") {
// Calcul du digit si naissance <=31/12/1999
// En clair : les 97 moins le MODULO(97) des 9 premiers
$sTDigit = 97 - fmod(substr($sTmpNbr, 0, 9), 97);
} else {
//Calcul du digit si naissance > 31/12/1999
//En clair : les 11 chiffres/97 moins le MODULO de 2+8 premiers chiffres
//chiffres par 97
$sTDigit = 97 - fmod("2".substr($sTmpNbr, 0, 9), 97);
}
//Les 2 derniers chiffres du numéro National doivent être équivalents
if ($sTDigit==substr($sTmpNbr, -2)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment