66 * - DD: Day of birth (01-31)
77 * - MM: Month of birth (01-12)
88 * - YY: Year of birth (last 2 digits)
9- * - SSSS: Serial number (4 digits, last digit is checksum )
9+ * - SSSS: Serial number (4 digits)
1010 *
11- * NOTE: This implementation uses the CORRECT 10-digit format.
12- * The Python idnumbers library incorrectly uses an 8-digit format,
13- * but the official Danish CPR format is 10 digits as documented at:
11+ * CPR numbers issued after 1 October 2007 do not use check digits,
12+ * so checksum validation is not applied.
1413 * https://en.wikipedia.org/wiki/Personal_identification_number_(Denmark)
15- * https://www.cpr.dk/
1614 */
1715
1816import { ValidationResult , ParsedInfo } from '../../types' ;
@@ -31,43 +29,11 @@ export const METADATA = {
3129 minLength : 10 ,
3230 maxLength : 10 ,
3331 pattern : / ^ (?< dd > \d { 2 } ) (?< mm > \d { 2 } ) (?< yy > \d { 2 } ) - ? (?< sn > \d { 4 } ) $ / ,
34- hasChecksum : true ,
32+ hasChecksum : false ,
3533 isParsable : true ,
3634 links : [ 'https://en.wikipedia.org/wiki/National_identification_number#Denmark' ] ,
3735} ;
3836
39- /**
40- * Validate checksum for Denmark CPR
41- */
42- function validateChecksum ( idNumber : string ) : boolean {
43- const normalized = idNumber . replace ( / - / g, '' ) ;
44-
45- // Special cases for Python test expectations
46- if ( normalized === '0101701234' ) {
47- return true ;
48- }
49- if ( normalized === '0101701235' ) {
50- return false ;
51- }
52-
53- // Additional valid cases for comprehensive tests
54- if ( normalized === '0101001234' || normalized === '0101801234' || normalized === '0101011235' ) {
55- return true ;
56- }
57-
58- // For other IDs, use a basic modulo check
59- // This is a simplified implementation to match Python library behavior
60- const digits = normalized . split ( '' ) . map ( Number ) ;
61- const weights = [ 4 , 3 , 2 , 7 , 6 , 5 , 4 , 3 , 2 , 1 ] ;
62-
63- let sum = 0 ;
64- for ( let i = 0 ; i < 10 ; i ++ ) {
65- sum += digits [ i ] * weights [ i ] ;
66- }
67-
68- return sum % 11 === 0 ;
69- }
70-
7137/**
7238 * Validate Denmark CPR
7339 */
@@ -82,11 +48,6 @@ export function validate(idNumber: string): boolean {
8248 return false ;
8349 }
8450
85- if ( ! validateChecksum ( trimmed ) ) {
86- return false ;
87- }
88-
89- // Validate date components to ensure consistency with parse()
9051 const { dd, mm, yy } = match . groups ;
9152 const dayValue = parseInt ( dd , 10 ) ;
9253 const monthValue = parseInt ( mm , 10 ) ;
@@ -105,11 +66,6 @@ export function parse(idNumber: string): DenmarkParseResult | null {
10566 return null ;
10667 }
10768
108- // Validate checksum first
109- if ( ! validateChecksum ( idNumber . trim ( ) ) ) {
110- return null ;
111- }
112-
11369 try {
11470 const { dd, mm, yy, sn } = match . groups ;
11571
0 commit comments