koblas / stdnum-js

A JavaScript library to provide functions to handle, parse and validate standard numbers.
MIT License
38 stars 26 forks source link

NO fodselsnummer - if the remainder is 0 you end up with 11 − 0 #101

Closed teebu closed 12 months ago

teebu commented 1 year ago

https://no.wikipedia.org/wiki/F%C3%B8dselsnummer if the remainder is 0 and you end up with 11 − 0, the check digit is 0, and not 11.

This seems to be a pretty common issue with other validators too.

values: 11111598403, 23114048690

should be valid

koblas commented 12 months ago

Yes, it does look like a consistent bug I dropped into a lot of places.

Thanks for continuing to find them!

teebu commented 12 months ago

Since this value represents a birthday, what do you think about adding future date invalidation?

koblas commented 12 months ago

The code is already doing that. :)

function checkBirthdate(value: string) {
  // eslint-disable-next-line prefer-const
  let [dd, mm, yy, rest] = strings
    .splitAt(value, 2, 4, 6, 9)
    .map(v => parseInt(v, 10));

  // Correct the birth day for D-numbers. These have a modified first digit.
  // https://no.wikipedia.org/wiki/F%C3%B8dselsnummer#D-nummer
  if (dd > 40) {
    dd -= 40;
  } 
  ....
teebu commented 12 months ago

What I meant is if the value is representing a DOB greater then today's date, not D or H number. Something like adding a param to isValidDate() that checks if its a future date.