Created
May 23, 2013 06:13
-
-
Save karlingen/5633052 to your computer and use it in GitHub Desktop.
SSN swedish validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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