Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improves validator and docs #4110

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading