Jump to content

[SOLVED] SIN number check


jordanwb

Recommended Posts

I'm making a function that validates a SIN number, but I'm stuck. I'm making the function based on the steps on this page: http://research.cs.queensu.ca/~bradbury/checkdigit/sincheck.htm Now I've gotten everything except the mod 10 bit:

 

function TestSinNumber ($sin_number)
{
$sin_number = ''.$sin_number;

$digits = str_split ($sin_number);

// Step 1
for ($i = 1; $i <= 7; $i += 2)
{
	$digits[$i] *= 2;
}

// Step 2
$sum = 0;	
for  ($i = 1; $i <= 7; $i += 2)
{
	$sum += ((int)($digits[$i] / 10)) + $digits[$i] % 10;
}

// Step 3
for ($i = 0; $i < 9; $i += 2)
{
	$sum += $digits[$i];
}

// Step 5
$rounded_up = round ($sum, -1);
$rounded_up = $rounded_up < $sum ? $rounded_up + 10 : $rounded_up;

print $rounded_up."<br />".$sum."<br />".$digits[8];

return $rounded_up - $sum == $digits[8]; 
}

 

**FIXED** It was an off by one error. I hate it when I post a topic then solve the problem 2 minutes later.  :-\

Link to comment
https://forums.phpfreaks.com/topic/136402-solved-sin-number-check/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.