South African ID Number Validation – There are many reasons a developer in South Africa would need to validate a South African ID number. They might need to validate the input on an Online order form. They might need it as a form of identification for a loan etc. How exactly do you do this? I’m sure that many of you have already found the Web Service to do this, but here is my take on it. A South African ID Number is made up as follows:
YYMMDDGSSSCAZ
YYMMDD : Date of birth (DOB)
G : Gender. 0-4 Female; 5-9 Male
SSS : Sequence No. for DOB/G combination
C : Citizenship. 0 SA; 1 Other
A : Usually 8, or 9 but can be other values
Z : Calculated control (check) digit
IF YOU CAME HERE FOR SOMETHING ELSE —> TRY THE FOLLOWING LINKS INSTEAD:
- Operation Not Legal in the Current State – Debugging ASP.NET Core
- EncryptValidate – My First NuGet Package
- Apple admits iPhone X display module issues
- Windows Task Manager – Resolve High Disk Usage
For more information, documentation and info on how the control digit is calculated, refer to SA ID Validator Web Page. What I did was to create a small application in Visual Studio 2010 (which is also available for download at the end of this post).
South African ID Number Validation – How To Do It
- In Visual Studio 2010, I created a simple Windows Forms Project and designed the form to include a text entry for the ID Number, a Validate Button and an Output field.
- In the Visual Studio Solution, Right Click on “Service References” and select “Add Service Reference”
- At the bottom of the Add Service Reference window, click on “Advanced”.
- In the Service Reference Settings screen, click on “Add Web Reference”. (Yes, we are adding a plain old Web Service Reference)
-
- In the Add Web Reference screen, specify the URL as follows:
http://xml-fx.com/services/SAIDValidator/SAIDValidator.asmxand click on the green arrow to the right of the URL field. -
Please note that this Web Service doesn’t seem to be active anymore. Instead consider using this instead from Sage Pay (you might need their SDK though to use it). South African ID validation technical guide
- In the Add Web Reference screen, specify the URL as follows:
Alternative online service to validate ID’s
-
Alternatively have a look at the pbVerify Verification API.
If anyone comes across another public web service to verify South African ID numbers, please share in the comments below.
- The documentation will be displayed in the screen. The saidvalidator service will be shown as found. Give the Web Reference a suitable name. Next click on “Add Reference”. The Visual Studio solution should now look as follows:
From here on, the code is fairly simple. Just add a using statement (Imports for the VB.Net folks out there):
using TestSAIDValidation.ValidateSAID;
Adding the code
Add the following code in the button click event:
string sSAID = txtSAID.Text.Trim();
TestSAIDValidation.ValidateSAID.saidType oReturn;
SAIDValidator oValidate = new SAIDValidator();
// authToken – Authentication token string. Currently can be set to any value including null
oReturn = oValidate.ValidateIdString(“authToken”, sSAID);
bool blnValidated = oReturn.Valid;
if (blnValidated)
{
saidTypeOutput oOutput = new saidTypeOutput();
oOutput = oReturn.output;
string DOB = oOutput.DOB.ToString(“dd MMMM yyyy”);
string Citizen = oOutput.Citizen.ToString();
string Gender = oOutput.Gender.ToString();
string Output = String.Format(“Valid SA ID Number{0}Date of Birth: ” + DOB + “{0}Citizen: ” + Citizen + “{0}Gender: ” + Gender, Environment.NewLine);
txtOutput.Text = Output;
}
else
{
txtOutput.Text = “Invalid SA ID Number”;
}
You should now have a working South African ID validation service. You can incorporate this into your own projects using your own best practices. Please note that the code and attached solution does not necessarily denote best practice. It is simply a solution to illustrate the Validation of a South African ID number. As always, any comments are welcome.
Download Visual Studio 2010 Solution.
Image: EWN