public class NorwegianIdNumber extends LocalIdNumber
k1 = 11 - ((3 * d1 + 7 * d2 + 6 * m1 + 1 * m2 + 8 * y1 + 9 * y2 + 4 * p1 + 5 * p2 + 2 * p3) % 11)
k2 = 11 - ((5 * d1 + 4 * d2 + 3 * m1 + 2 * m2 + 7 * y1 + 6 * y2 + 5 * p1 + 4 * p2 + 3 * p3 + 2 * k1) % 11)
kn
representing the n
-th control number and d
, m
, y
, p
equally presenting
the day, month or year of birth as given by the fødselsnummer and p
meaning a digit of the personnummer.
The third digit of the personnummer gives information about the gender of a person with even digits for female and odd digits for male persons. The exact birth year can be deducted from the known last two digits together with the personnummer where the first three digits of the personnummer determines:
Note that a Norwegian ID number's validity is dependant of the type as defined by NorwegianIdNumber.Type
.
NorwegianIdNumber.Type
,
IdNumber
Modifier and Type | Class and Description |
---|---|
static class |
NorwegianIdNumber.Type
Describes the type of the given Norwegian ID.
|
Constructor and Description |
---|
NorwegianIdNumber(String idToken)
Creates a new Norwegian id number representation with Norwegian locale.
|
NorwegianIdNumber(String idToken,
Locale locale)
Creates a new Norwegian id number representation with the given locale.
|
Modifier and Type | Method and Description |
---|---|
Optional<LocalDate> |
birthday()
Extracts the birthday of this ID.
|
static Optional<LocalDate> |
birthday(IdNumber idNumber)
Extracts the birthday of the given ID.
|
static NorwegianIdNumber |
forId(String idToken)
Convenience constructor method for creating a Norwegian ID with Norwegian locale.
|
static NorwegianIdNumber |
forId(String idToken,
Locale locale)
Convenience constructor method for creating a Norwegian ID with the given locale.
|
Optional<Gender> |
gender()
Extracts the gender of this ID.
|
static Optional<Gender> |
gender(IdNumber idNumber)
Extracts the gender of the given ID.
|
boolean |
isValid()
Checks the validity of this ID.
|
protected boolean |
supports(Locale locale)
Defines support method for given locale.
|
Optional<NorwegianIdNumber.Type> |
type()
Extracts the type of this ID.
|
static Optional<NorwegianIdNumber.Type> |
type(IdNumber idNumber)
Extracts the type of the given ID.
|
static boolean |
valid(IdNumber idNumber)
Checks the validity of a given ID.
|
public NorwegianIdNumber(String idToken)
idToken
- The id token for this id.public static NorwegianIdNumber forId(String idToken)
idToken
- The token for this id.public static NorwegianIdNumber forId(String idToken, Locale locale)
idToken
- The token for this id.locale
- The locale of the ID.public static Optional<Gender> gender(IdNumber idNumber)
idNumber
- The ID to be examined.public Optional<Gender> gender()
public static boolean valid(IdNumber idNumber)
idNumber
- The ID to be examined.true
if the given ID is valid by measures of the Norwegian ID definition.public boolean isValid()
true
if this ID is valid by measures of the Norwegian ID definition.public static Optional<LocalDate> birthday(IdNumber idNumber)
idNumber
- The ID to be examined.public Optional<LocalDate> birthday()
public static Optional<NorwegianIdNumber.Type> type(IdNumber idNumber)
idNumber
- The ID to be examined.public Optional<NorwegianIdNumber.Type> type()
protected boolean supports(Locale locale)
LocalIdNumber
supports
in class LocalIdNumber
locale
- given locale.