Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@karlingen
Created May 23, 2013 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karlingen/5633052 to your computer and use it in GitHub Desktop.
Save karlingen/5633052 to your computer and use it in GitHub Desktop.
SSN swedish validation
<?php
/**
* Checks if the given number is a valid SSN (in Sweden)
*/
protected function checkSSNValidity($ssn)
{
if (strlen($ssn) != 10)
{
return false;
}
$n = 2;
for ($i=0; $i<9; $i++) {
$tmp = $ssn[$i] * $n;
($tmp > 9) ? $sum += 1 + ($tmp % 10) : $sum += $tmp; ($n == 2) ? $n = 1 : $n = 2;
}
return !( ($sum + $ssn[9]) % 10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment