File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -87,16 +87,16 @@ export function validateOrganizationNumber(
8787type PersonalIdentityNumberOptions = ValidatorOptions ;
8888
8989/**
90- * Validates that the input value is a Swedish national identity number (fødselsnummer or d-nummer ).
90+ * Validates that the input value is a Swedish national identity number (personnummer or samordningsnummer ).
9191 *
9292 * It validates the control digits and checks if the date of birth is valid.
9393 *
9494 * @example
9595 * ```
96- * // Fødselsnummer
96+ * // Personnummer
9797 * validatePersonalIdentityNumber('21075417753') // => true
9898 *
99- * // D-nummer
99+ * // Samordningsnummer
100100 * validatePersonalIdentityNumber('53097248016') // => true
101101 * ```
102102 */
@@ -130,6 +130,12 @@ export function validateNationalIdentityNumber(
130130 year = 2000 ;
131131 }
132132
133+ // for a d-number the day is increased by 40. Eg the 31st of a month would be 71, or the 3rd would be 43.
134+ // thus we need to subtract 40 to get the correct day of the month
135+ if ( day > 40 ) {
136+ day = day - 40 ;
137+ }
138+
133139 return isValidDate ( year , month , day ) ;
134140}
135141
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ export function mod10(value: string): boolean {
5757}
5858
5959export function isValidDate ( year : number , month : number , day : number ) : boolean {
60- // months are zero indexed 🤷♂️
60+ // biome-ignore lint/style/noParameterAssign: months are zero index 🤷♂️
6161 month -= 1 ;
6262
6363 // important to use UTC so the user's timezone doesn't affect the validation
You can’t perform that action at this time.
0 commit comments