John Davidson

php - Is there a known way to validate an Estonian business ID?

0 comments
Message:


I have to validate an Estonian business ID (not a citizen ID). The ID is 9 numbers, but I think there might be a system of assigning them. For example, here is the Finnish validation with the last number as the checksum


if (preg_match('/^\d{7}-\d{1}$/', $user_input)) {
list($num, $control) = preg_split('[-]', $user_input);
// Add leading zeros if number is < 7
$num = str_pad($num, 7, 0, STR_PAD_LEFT);
$controlSum = 0;
$controlSum += (int)substr($num, 0, 1)*7;
$controlSum += (int)substr($num, 1, 1)*9;
$controlSum += (int)substr($num, 2, 1)*10;
$controlSum += (int)substr($num, 3, 1)*5;
$controlSum += (int)substr($num, 4, 1)*8;
$controlSum += (int)substr($num, 5, 1)*4;
$controlSum += (int)substr($num, 6, 1)*2;
$controlSum = $controlSum%11;
if ($controlSum == 0) {
return ($controlSum == $control) ? true : false;
} elseif ($controlSum >= 2 && $controlSum <= 10 ) {
return ((11 - $controlSum) == $control) ? true : false;
}
}

Usually there is a checksum for all of these types of IDs, so it's not just a matter of running a regex on it, but I can't find anything relating to Estonian businesses.


Any links to known libraries, examples would be appreciated. I'm working in PHP, but these could be in any language.


Thanks.



My Answer:
less than 7 digits
$num = str_pad($num, 7, "0", STR_PAD_LEFT);

// Calculate checksum
$multipliers = array(7, 9, 10, 5, 8, 4, 2);
$sum = 0;
for ($i = 0; $i < 7; $i++) {
$sum += $num[$i] * $multipliers[$i];
}
$checksum = $sum % 11;

// Compare checksum with control number
if ($checksum == $control) {
echo "Valid Finnish business ID";
} else {
echo "Invalid Finnish business ID";
}
} else {
echo "Invalid format";
}

For Estonian business IDs, you can check if the ID is 9 digits and then validate it according to the checksum algorithm used in Estonia. You may need to research the specific algorithm used for Estonian business IDs or consult official sources for more information.

Rate this post

4 of 5 based on 5605 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us