koblas / stdnum-js

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

German National ID number (Personalausweisnummer) #43

Closed teebu closed 1 year ago

teebu commented 1 year ago

Can you add DE Personalausweisnummer regex: ^[lmnprtvwxy][0-9cfghjklmnprtvwxyz]{8}[0-9][d]?

some Refs: http://www.pruefziffernberechnung.de/P/Personalausweis-DE.shtml https://learn.microsoft.com/en-us/microsoft-365/compliance/sit-defn-germany-identity-card-number?view=o365-worldwide https://www.php-einfach.de/diverses/personalausweis-ueberpruefen/

It's alpha char convert to digit (if present) and a repeating weight of 7,3,1 and the check digit is last digit, sometimes has optional 'D' in the value in the end.

First, the letters are converted into numbers. An A becomes 10, a B becomes 11, and so on.
Then each digit is multiplied by a value.
The first digit is multiplied by the value 7, the second by the value 3, and the third digit by the value 1. Then this sequence starts over.
The check digit is then the last digit of the sum over the previous multiplications.
koblas commented 1 year ago

Should now be available -> PR #45 should add it.

teebu commented 1 year ago

I can't find any site talking about the length of Personalausweisnummer as being 24.

Can you add tests for short format.

Here's some I scraped from the sample sites - added optional D:

'2406055684',
'2406055684d',
'2406055684D',
'T220001293D',
'T220001293',
'L01X00T471'

https://github.com/koblas/stdnum-js/blob/1b1933e79e9d1703dad8e423b27805a1dbb385b0/src/de/pwnr.spec.ts

I found this that mentions German ID being 29 digits (24 if not including optional fields), and includes gender value. The regex they show almost matches your tests.

https://docs.trellix.com/bundle/data-loss-prevention-11.10.x-classification-definitions-reference-guide/page/GUID-B0C0EED8-DFF5-44A0-B453-B6CCF41BF739.html

(?i:\b[0-9A-Z]{9}[0-9]D?[ -]?[0-9]{6}[0-9][ -MF]?[0-9]{6}[0-9][ -]?[0-9]\b)

Matches a 29-character long alphanumeric string, where:

Character 1–9 is a digit from [0–9] or an alphanumeric character from [A-Z]
Character 10 is a digit from [0–9].
Character 11 is an optional character that starts with the letter 'D'.
Character 12 is delimited with space or hyphen (optional).
Character 13–19 is a digit from [0–9].
Character 20 is delimited with space or hyphen or a letter 'M' or 'F' (optional).
Character 21–27 is a digit from [0–9].
Character 28 is delimited with space or hyphen (optional)
Character 29 is a digit from [0–9].

Bug in test: https://github.com/koblas/stdnum-js/blob/1b1933e79e9d1703dad8e423b27805a1dbb385b0/src/de/pwnr.ts#L67

missing .test()

koblas commented 1 year ago

PR #48 should resolve all of these issues, please review and let me know.

teebu commented 1 year ago

Looks good, I have yet to find documentation on the "new" 26 length format, because the "new" and current format is the 11, it is used in the ID of a German person I talked to. The previous one didn't have letters, as Microsoft points out.

Can you point me where you found it?

koblas commented 1 year ago

The first set of numbers is a combination of the issuing agency and a sequence number. If you review the list most of these are numeric, but it looks like most of the E-Pass (whatever that is, have alphanumeric coding)

http://www.pruefziffernberechnung.de/Begleitdokumente/BKZ.shtml

teebu commented 1 year ago

I think I see now, its found here http://www.pruefziffernberechnung.de/R/Reisepass-DE.shtml

The 11 digits (passport serial) + dob + some other numbers = 26 chars