I have been wondering if there is the possibility of validating that big number that is the unique code for every SIM card on the planet, the ICCID.
If there is, does anyone have the code to check if it is valid on a T-SQL function?
I would like to do it without the need of any programming language out of the database.
I found this code on C# but I am unnable to convert it to SQL because I just suck at math and c# and this <<
operator just ended me!
private bool IccidIsValid(string iccid)
{
try
{
int numberStringLength = 18;
int cs = 0;
int dodd;
for (int i = 0; i < numberStringLength; i += 2)
{
dodd = Convert.ToInt32(iccid.Substring(i + 1, 1)) << 1;
cs += Convert.ToInt32(iccid.Substring(i, 1)) + (int)(dodd / 10) + (dodd % 10);
}
cs = (10-(cs % 10)) % 10;
if (cs == Convert.ToInt32(iccid.Substring(numberStringLength, 1)))
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
return false;
}
}
I Found it!
I just remade the Internet version to make it faster without the need of a temporary table: