Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bug #16709 New SSN rules in Denmark

  • Loading branch information...
commit 574c5e7de38489ad185e97bb9135e1b838bd6e57 1 parent 4de4c05
@CloCkWeRX CloCkWeRX authored
Showing with 14 additions and 12 deletions.
  1. +5 −8 Validate/DK.php
  2. +9 −4 tests/validate_DK.phpt
View
13 Validate/DK.php
@@ -85,16 +85,12 @@ function postalCode($postcode, $strong=false)
*/
function ssn($cpr, $gender = false)
{
- static $control = array(4, 3, 2, 7, 6, 5, 4, 3, 2, 1);
-
// remove spaces and uppercase it
- $preg = "/^[0-9]{6}\-?[0-9]{4}$/";
+ $preg = "/^[0-3][0-9][0-1]\d{3}-\d{4}?/";
if (preg_match($preg, $cpr)) {
+
$cpr = str_replace('-', '', $cpr);
- $controlCipher = 0;
- for ($i = 0; $i < count($control); $i++) {
- $controlCipher += $control[$i] * substr($cpr, $i, 1);
- }
+
$y = substr($cpr, -1);
switch ($gender) {
case 'M':
@@ -107,7 +103,8 @@ function ssn($cpr, $gender = false)
$genderOK = true;
break;
}
- return ((($controlCipher % 11) === 0) && ($genderOK));
+
+ return $genderOK;
} else {
return false;
}
View
13 tests/validate_DK.phpt
@@ -47,15 +47,19 @@ $ssns = array(
array(
'01a19.-1212',
false // no gender (wrong format)
- ), // NOK !(is male)
+ ), // NOK !(wrong format)
array(
'no-way',
false // no gender (wrong format)
- ), // NOK !(is male)
+ ), // NOK !(wrong format)
array(
'010192-1211',
false // no gender
- ) // NOK (cipher does not match)
+ ), // OK (cipher does not match)
+ array(
+ '012092-1211',
+ false // no gender
+ ) // NOK (Wrong format)
);
$carregs = array(
@@ -101,7 +105,8 @@ Test ssn
010192-1212, M: NO
01a19.-1212, : NO
no-way, : NO
-010192-1211, : NO
+010192-1211, : YES
+010120-1211, : NO
Test phonenumber
21021212: YES
2121212: NO
Please sign in to comment.
Something went wrong with that request. Please try again.