Skip to content

Commit

Permalink
improves validator and docs (#4110)
Browse files Browse the repository at this point in the history
  • Loading branch information
langz authored Oct 10, 2024
1 parent a7f05f8 commit 9e2b511
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { NationalIdentityNumberProperties } from '@dnb/eufemia/src/extensions/fo
- `dnrAndFnrValidator`:
- validates the identification number as a D number when first digit is 4 or greater (because a D number has its first number increased by 4).
- validates the identification number as a national identity number (fødselsnummer) when first digit is 3 or less.
- `adultValidator`: validates if the identification number has a date of birth that is 18 years or older. It uses only the 9 first digits of an identification number to validate, first 6 digits representing the birth of date, and the next three digits are individual numbers. It does not validate the identification number, therefore it's quite common to use this validator together with one of the validators above (`dnrValidator`, `fnrValidator` or `dnrAndFnrValidator`) to validate the identification number as well.
- `adultValidator`: validates if the identification number has a date of birth that is 18 years or older. It uses only the 7 first digits of an identification number to validate, first 6 digits representing the birth of date, and the next digit represents the century. It does not validate the identification number, therefore it's quite common to use this validator together with one of the validators above (`dnrValidator`, `fnrValidator` or `dnrAndFnrValidator`) to validate the identification number as well.

You can create your own `adultValidator` by using the `createAboveAgeValidator` function. It takes an age as a parameter and returns a validator function. The validator function takes a value and returns an error message if the value is not above the given age.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ export function getBirthDateByFnrOrDnr(value: string) {
}

const yearPart = value.substring(4, 6)
const individualNumber = Number.parseInt(value.substring(6, 9))
const centuryNumber = Number.parseInt(value.substring(6, 7))

const isBornIn20XX = individualNumber >= 500 && individualNumber <= 999
const isBornIn20XX = centuryNumber >= 5
const year = isBornIn20XX ? `20${yearPart}` : `19${yearPart}`
const month = Number.parseInt(value.substring(2, 4))

Expand Down

0 comments on commit 9e2b511

Please sign in to comment.