I've needed to do this a few times, so I've published a library for it
I’ve been on a few projects where the user is signing up to a system that requires them to enter their ID number. Before you cringe too hard, these are actually in situations where you would normally expect to need to enter your ID, such as signing up for a medical aid, checking your credit profile, or creating an investment account.
As a South African myself, the vast majority of my clients are South African, and the majority of their customers filling in these forms have South African ID numbers.
A South African ID number actually contains a fair amount of information about a person that you can use to make the sign up process a bit quicker for most people in most cases, such as their date of birth, their sex according to the government, and whether or not they are a citizen of South Africa (a permanent resident may have an ID number without having citizenship).
I would not advocate using the ID number to validate any information except that the ID number itself is in a valid format (13 digits, with the last digit being a checksum). There will be edge cases regarding the other information not matching that might end up preventing valid users from using your system. For example, someone may have recently become a citizen of South Africa, but does not have a new ID number yet because beaurocratic systems tend to take a while.
I think it is a good idea to use the ID number to pre-populate these fields. It will be correct for most people, and saves them a bit of typing to get all of their information onto your system.
The best writeup that I’ve found of how to get this information from the ID number was written a few years ago by Evan Knowles here. The outcome of Evan’s investigation into ID numbers was an excellent Chrome extension for generating random valid ID numbers for testing purposes. My desired outcome is a little bit different.
I would like to have a library that I can use for extracting that information from an ID number that the user entered on a web form, and use it to make a process less painful and less error prone. I’d like to be able to use this library on the frontend, to prepopulate forms and do client side validation, and if I happen to be running Node I’d like to be able to use the same library on the server as well.
I have written such a library. It’s available now on NPM. Please use it if you have this ID parsing and validation problem in your project as well. The Node version has been ready for a while, but I only recently updated it to work in the browser as well.
npm install --save south-african-id-parser
If you run into trouble with my library, feel free to open a Github issue, or create pull requests.