HermannBjorgvin / Kennitala

Icelandic national ID (kennitölur) utilities for servers and clients.
MIT License
36 stars 10 forks source link

Invalid date is accepted as valid kennitala #21

Closed MiniGod closed 1 week ago

MiniGod commented 2 years ago

The isPerson validation does not account for invalid dates. I see the current code simply checks that the day is <= 31, but 310222 for instance is not a valid date, and hence not a valid kennitala.

Would have to parse the date and validate it.

One way to do it:

const isValid = isNaN(new Date('2022-02-31').getTime())

Related to #16

HermannBjorgvin commented 2 years ago

Interesting. Not a bad idea to validate the months.

HermannBjorgvin commented 2 years ago

This has been implemented on the v2 branch, you can try yarn add kennitala@2.0.0-beta.0 to test it out.

HermannBjorgvin commented 1 week ago

Available in V2.0.2 now non-beta.