Geeks With Blogs
Willem's... {rue if I mellow}

[South African Specific]

### SAIDValidator Webservice

SAIDValidator is an ASP.NET webservice to validate South African Person ID numbers. It provides validation of a person ID by calculating the check-digit (digit-13), and extracts the date-of-birth, gender, citizenship, sequence and other information. The following links are available:

### South African Department of Home Affairs

If you would like to check your SA Passport or ID application status, or your current official marital status, please click on the link below:

### How to validate SA Identity Numbers

An enigmatic quest indeed, with no definitive standards published by any SA government department known.  The following blogs show the basics for validating SA Identity numbers:

Here's my interpretation and short code-excerpt for validating 'digit-13', the so-called 'check' digit:

Format:
{YYMMDD}{G}{SSS}{C}{A}{Z}
YYMMDD : Date of birth.
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 [can be other values]
Z  : Control digit calculated in the following section:

Formula to calculate the check digit for a 13 digit identity number:

According to the provisions of the Identification Amendment Act, 2000 (Act No. 28 of 2000,
which was promulgated on 13 October 2000) all forms of identity documents other than the
green bar-coded identity document are invalid. [my observation: the following algorithm appears to work for the older 'blue'-book id numbers as well].  In accordance with the legislation,
the control figure which is the 13th digit of all identity numbers which have 08 and 09 is
calculated as follows using ID Number 800101 5009 087 as an example:

• Add all the digits in the odd positions (excluding last digit).
8 + 0 + 0 + 5 + 0 + 0 = 13...................[1]
• Move the even positions into a field and multiply the number by 2.
011098 x 2 = 22196
• Add the digits of the result in b).
2 + 2 + 1 + 9 + 6 = 20.........................[2]
13 + 20 = 33
• Subtract the second digit (i.e. 3) from 10.  The number must tally with the last number in the ID Number. If the result is 2 digits, the last digit is used to compare against the last number in the ID Number.  If the answer differs, the ID number is invalid.

Here's the digit-13 check C# code
[Check below for a validator using a working version of this code]
:

 `// This method assumes that the 13-digit id number has // valid digits in position 0 through 12. // Stored in a property 'ParseIdString'. // Returns: the valid digit between 0 and 9, or // -1 if the method fails.private int GetControlDigit(){ int d = -1; try { int a = 0; for(int i = 0; i < 6; i++) { a += int.Parse(this.ParsedIdString[2*i].ToString()); } int b = 0; for(int i = 0; i < 6; i++) { b = b*10 + int.Parse(this.ParsedIdString[2*i+1].ToString()); } b *= 2; int c = 0; do { c += b % 10; b = b / 10; } while(b > 0); c += a; d = 10 - (c % 10); if(d == 10) d = 0; } catch {/*ignore*/} return d;}`

Related Posts on Geeks With Blogs Matching Categories

Comments on this post: How to validate SA Identity Numbers

# re: How to validate SA Identity Numbers
I needed to convert to vb.net so here is my code if anybody needs a conversion in a hurry:

Public Function parseIdNo(ByVal idNo As String) As Boolean
Try
Dim a As Integer = 0
For i As Integer = 0 To 5
a += CInt(idNo.Substring(i * 2, 1))
Next

Dim b As Integer = 0
For i As Integer = 0 To 5
b = b * 10 + CInt(idNo.Substring(2 * i + 1, 1))
Next
b *= 2
Dim c As Integer = 0
Do
c += b Mod 10
b = Int(b / 10)
Loop Until b <= 0
c += a
Dim d As Integer = 0
d = 10 - (c Mod 10)
If (d = 10) Then d = 0
If d = CInt(idNo.Substring(12, 1)) Then
Return True
Else
Return False
End If
Catch ex As Exception
Return False
End Try
End Function
Left by Clive on Dec 08, 2005 4:58 AM

# re: How to validate SA Identity Numbers
Clive, thanks for the contribution!
Left by Willem on Dec 08, 2005 7:55 AM

# re: How to validate SA Identity Numbers
James, v.cool - thanks!
Left by Willem on Dec 09, 2005 11:06 AM

# How to validate Namibian Identity Numbers
Is their a similar procedure available to validate Namibian ID numbers?
Left by Hannes on Jan 04, 2006 2:08 PM

# Namibian ID numbers
Not sure - definitely *NO* info out there... won't it be similar to SA ID numbers? ..remember SA governed Namibia not so long ago when it was South West Africa.
Left by Willem on Jan 31, 2006 11:50 AM

# re: How to validate SA Identity Numbers
Does anybody know of a readily accessible portal at which a ID number can be checked against a known identity (without having to subscribe to ITC). The www.elections.org.za worked fine for me in order to confirm identity, as you could enter a valid ID and it would return First names and Surname along with voting district. I ran a small hot script that would post ID number to the URL and checked relevant returned html text for match. Recently (probably because elections are passed) the site stopped supplying names, but only confimed whether registered or not...Any ideas...
Left by Patrick Maloney on Mar 16, 2006 4:48 PM

# re: How to validate SA Identity Numbers
You guys are stars thank you!!!!. the vb conversion made a huge difference to my friday :D
Left by Louise on Aug 04, 2006 8:44 AM

# re: How to validate SA Identity Numbers
Any ideas on whether there is something similar to an ID number for Kenya.
Left by Amnon on Jan 17, 2007 2:58 PM

# re: How to validate SA Identity Numbers
Any ideas on whether there is something similar to an ID number for Kenya. j1@eighty20.co.za
Left by Amnon on Jan 17, 2007 2:59 PM

# re: How to validate SA Identity Numbers
Did you know: The current SA ID Number algorithm was created by my uncle Pieter den Boer (ex Q-Data, Brainware...) while working at IBM in the 1980's. He passed away last week - I attended his funeral this morning. A great mathematical mind an Business man will sorely be missed.
Left by Henk Sweers on Jan 18, 2007 3:13 PM

# re: How to validate SA Identity Numbers
Hi all,

What do ID numbers for birthdates in 2000 and later look like? How do you validate numbers like that?

Any ideas would be great!
Left by Peter Davies on Jan 24, 2007 10:22 AM

# re: How to validate SA Identity Numbers
Thank you for this!
Left by Johan Andersson on Jan 29, 2007 10:25 AM

# re: How to validate SA Identity Numbers
From 2000 on the year starts at '00', again. I assume that if there are SA citizens with an ID from the year 1900, that this would use the same year number: '00'. The 'SSS' sequence would make the number unique. However, I am not sure if you can distinguish a '1900' ID from a '2000' ID etc.
A valid year 2000 ID is:
0005205113086 for a birthdate: 20 May 2000.

Anyone with clarity on this???
Left by Willem on Jan 29, 2007 10:48 AM

# re: How to validate SA Identity Numbers
When passed an input string which is the IDNumber, how can I return a valid vb.net date?
Left by Johan on Feb 02, 2007 12:49 PM

# re: How to validate SA Identity Numbers
If you are looking for a specific person's ID number, I can help.
Left by HeinRich on Feb 07, 2007 4:19 AM

# re: How to validate SA Identity Numbers
Dept of Home Affairs has a tool you can at least use to verify marital status (hence existence) at http://www.dha.gov.za/enquiry/marital/status/marital_status.asp
Left by James on May 02, 2007 6:28 AM

# re: How to validate SA Identity Numbers
James, Nice link - not only confirms whether the person attached to the ID number is married/single, but also whether the entered ID number is (a) valid, and (b) if valid whether it is a real live ID number.

Hmmm, see DHA have a warning about using it for non-personal use.... would be interesting to see how they enforce that....

Left by Willem Fourie on May 02, 2007 11:30 AM

# re: How to validate SA Identity Numbers
An old ex Zimbo friend of mine is a permanant resident but long time ago lost his ID book. When he wanted to replace it 10 years later DHA are demanding his ID number. He has long forgotton it! Can anyone help using his DOB or permanant residence number. He does not want to go back to DHA.
Left by Peter on May 05, 2007 12:45 PM

# re: How to validate SA Identity Numbers
I have had to modify my original VB.NET post to cater for erroneous idNo's like 0000000024588

Its not very ellegant and wont get us into the next century, but then again neither will VB.NET.

Public Function parseIdNo(ByVal idNo As String) As Boolean
Try
Dim a As Integer = 0
For i As Integer = 0 To 5
a += CInt(idNo.Substring(i * 2, 1))
Next

Dim b As Integer = 0
For i As Integer = 0 To 5
b = b * 10 + CInt(idNo.Substring(2 * i + 1, 1))
Next
b *= 2
Dim c As Integer = 0
Do
c += b Mod 10
b = Int(b / 10)
Loop Until b <= 0
c += a
Dim d As Integer = 0
d = 10 - (c Mod 10)
If (d = 10) Then d = 0
If (d = CInt(idNo.Substring(12, 1))) And (IsDate("19" & idNo.Substring(0, 2) & "/" & idNo.Substring(2, 2) & "/" & idNo.Substring(4, 2)) Or IsDate("20" & idNo.Substring(0, 2) & "/" & idNo.Substring(2, 2) & "/" & idNo.Substring(4, 2))) Then
Return True
Else
Return False
End If
Catch ex As Exception
Return False
End Try
End Function
Left by Clive on May 10, 2007 7:09 AM

# re: How to validate SA Identity Numbers
Here is the same routine in PHP,

public static function validateIdNumber(\$id) {
\$match = preg_match ("!^(\d{2})(\d{2})(\d{2})\d{7}\$!", \$id, \$matches);
if (!\$match) {
return false;
}

list (, \$year, \$month, \$day) = \$matches;

/**
* Check that the date is valid
*/
if (!checkdate(\$month, \$day, \$year)) {
return false;
}

/**
* Now Check the control digit
*/
\$d = -1;

\$a = 0;
for(\$i = 0; \$i < 6; \$i++) {
\$a += \$id{2*\$i};
}

\$b = 0;
for(\$i = 0; \$i < 6; \$i++) {
\$b = \$b*10 + \$id{2*\$i+1};
}
\$b *= 2;

\$c = 0;
do {
\$c += \$b % 10;
\$b = \$b / 10;
} while(\$b > 0);

\$c += \$a;
\$d = 10 - (\$c % 10);
if(\$d == 10) \$d = 0;

if (\$id{strlen(\$id)-1} == \$d) {
return true;
}

return false;
}
Left by dawit on Jul 16, 2007 6:29 AM

# IDENTITY NUMBERS SHARED
On Saturday, 28 July 2007, my wife (PG Nosi) and bought a television. We found out that she shares her identity number (7602210298085) with a certain Mr Paul Nkosi.

I need to find out how could a female and a male share the same identity number?

We all know that female ID numbers start with the number 0 after date of birth and the male ID numbers start with the number 5.

This is a worrying situation, especially with the recent corruption reports that we get regarding the Home Affairs Department.

Concerned
Norman Nosi
Left by Monnapule Norman Nosi on Jul 30, 2007 1:45 AM

# re: How to validate SA Identity Numbers
Hi there,

Can you please advise if this works for both old and new ID numbers??

Thanks
K
Left by Kats on Aug 10, 2007 2:52 AM

# re: How to validate SA Identity Numbers
How do I determine the race group from the id?
Left by Sarika Maharaj on Sep 03, 2007 6:15 AM

# re: How to validate SA Identity Numbers
As far as I know the race-group info is NOT encoded into the id number.
Left by Willem Fourie on Sep 04, 2007 7:09 AM

# re: How to validate SA Identity Numbers
hello all i was wondering if you can tell a persons race from the South African ID number

eg: Black;White;Coloured;Idian etc.....

any one know??

Left by Philip on Oct 03, 2007 8:17 AM

# PHP Script and dates
hello again

i am busy writing a php script which will process the id number i am having problems though with birth dates after 1970 because php only supports up to 1970 any ideas

thank you
Left by Philip on Oct 04, 2007 7:37 AM

# re: How to validate SA Identity Numbers
Hi Guys, I tried to find a SQL Implementation of this function but Google failed me but I still know one exists. Anyway, I wrote the SP myself. Let me know what you think:

-- =============================================
-- Author: Craig Peacock
-- Create date: 08/10/2007
-- Description: This will validate a SA ID Number
-- =============================================
ALTER PROCEDURE [dbo].[VAL_S01_ValidateSAIDNumber]
@IDNumber VARCHAR (13)
AS
BEGIN

/*
This function was created from the function posted at:
http://geekswithblogs.net/willemf/archive/2005/10/30/58561.aspx
*/

DECLARE @A INT -- ~Holds Negative Index numbers
DECLARE @B INT -- ~Holds Positive Index numbers
DECLARE @C INT

DECLARE @D INT -- ~The check digit
DECLARE @I INT -- ~Counter Variable

SET @D = -1

SET @A = 0
SET @B = 0

BEGIN TRY

PRINT 'Getting Negative Numbers____________________'
SET @I = 0

WHILE (@I < 6)
BEGIN

PRINT SUBSTRING(@IDNumber, 2 * @I + 1, 1)

SET @A = @A + CAST(SUBSTRING(@IDNumber, 2 * @I + 1, 1) AS INT)
SET @I = @I + 1
END --WHILE

PRINT 'Getting Positive Numbers____________________'
SET @I = 1

WHILE (@I < 7)
BEGIN

PRINT SUBSTRING(@IDNumber, 2 * @I + 1, 1)

SET @B = @B * 10 + CAST(SUBSTRING(@IDNumber, 2 * @I, 1) AS INT)
SET @I = @I + 1

END --WHILE

SET @B = @B * 2
SET @C = 0

WHILE (@B > 0)
BEGIN

SET @C = @C + @B % 10
SET @B = @B / 10

END --WHILE

SET @C = @C + @A
SET @D = 10 - (@C % 10)

IF (@D = 10)
SET @D = 0

IF (CAST(SUBSTRING(@IDNumber, 13, 1) AS INT) = @D)
RETURN 1
ELSE
RETURN 0

END TRY
BEGIN CATCH
RETURN 0
END CATCH

RETURN 0

END
Left by Craig Peacock on Oct 09, 2007 2:16 AM

# re: How to validate SA Identity Numbers
Here is a Javascript version I wrote about 5 years ago, still seems to work...

function SAIDValidate()
{
//private method CalcSumOfString
this.CalcSumOfString = function(ValueToSum)
{
var lenghtOfString = ValueToSum.length;
var sumOfString=0;
for (var i = 0;i < lenghtOfString;i++)
{
sumOfString += parseInt(ValueToSum.substr(i,1));
}
return sumOfString;
}

//private method SAIDCheck
this.SAIDCheck = function (IdNumber)
{
var d1 = 0;
var d2 = 0;
var d3 = 0;
var d4 = 0;
var d5 = 0;
var d6 = 0;
var d7 = 0;
var d8 = 0;
var d9 = 0;
var d10 = 0;
var d11 = 0;
var d12 = 0;
var d13 = 0;
var evsum = 0;
var odsum = 0;
var evnum1 = 0;
var evnum2 = 0;
var evnum3 = 0;
var evnum4 = 0;
var evnum5 = 0;
var evnum6 = 0;
var checkDigit = 0;
if (IdNumber.length == 13 )
{
d1 = parseInt(IdNumber.substr(0,1),10);
d2 = parseInt(IdNumber.substr(1,1),10);
d3 = parseInt(IdNumber.substr(2,1),10);
d4 = parseInt(IdNumber.substr(3,1),10);
d5 = parseInt(IdNumber.substr(4,1),10);
d6 = parseInt(IdNumber.substr(5,1),10);
d7 = parseInt(IdNumber.substr(6,1),10);
d8 = parseInt(IdNumber.substr(7,1),10);
d9 = parseInt(IdNumber.substr(8,1),10);
d10 = parseInt(IdNumber.substr(9,1),10);
d11 = parseInt(IdNumber.substr(10,1),10);
d12 = parseInt(IdNumber.substr(11,1),10);
d13 = parseInt(IdNumber.substr(12,1),10);
evnum1 = (d2 * 2);
evnum2 = (d4 * 2);
evnum3 = (d6 * 2);
evnum4 = (d8 * 2);
evnum5 = (d10 * 2);
evnum6 = (d12 * 2);
evsum = (this.CalcSumOfString(evnum1.toString())) + (this.CalcSumOfString(evnum2.toString()))+ (this.CalcSumOfString(evnum3.toString()))+ (this.CalcSumOfString(evnum4.toString()))+ (this.CalcSumOfString(evnum5.toString()))+ (this.CalcSumOfString(evnum6.toString()));
odsum = d1 + d3 + d5 + d7 + d9 + d11;
if ( ((evsum + odsum) % 10) == 0 )
checkDigit = 0;
else
checkDigit = 10 - ((evsum + odsum) % 10);

if (checkDigit != d13)
return false;
else
return true;
}
else
{
return false;
}
}
}
Left by Martin on Nov 02, 2007 9:18 AM

# re: How to validate SA Identity Numbers
Here's another Javascript version:

function validateID(idVal){
var checkDigit = parseInt(idVal.charAt(idVal.length - 1));
var odd = 0;
var even = "";
var evenResult = 0;
var result;
for(var c = 1; c <= idVal.length; c++){
if(c % 2 == 0){
even += idVal.charAt(c - 1);
} else{
if(c == idVal.length){
continue;
} else{
odd = (parseInt(odd) + parseInt(idVal.charAt(c - 1)));
}
}
}
even = (Number(even) * 2);
even = even.toString();
for(var r = 1; r <= even.length; r++){
evenResult = (parseInt(evenResult) + parseInt(even.charAt(r - 1)));
}
result = (parseInt(odd) + parseInt(evenResult));
result = result.toString();
result = (10 - parseInt(result.charAt(result.length - 1)));
result = result.toString();
if(result.length > 1){
result = result.charAt(result.length - 1);
}
if(parseInt(result) != checkDigit){
return false;
} else{
return true;
}
}
Left by Phillip on Nov 07, 2007 3:01 AM

# re: How to validate SA Identity Numbers
Willem and Craig, I tried the SQL previously on the blog and it worked (old and new numbers). Craig's one doesn't seem to work though (unless it is a SQL version problem). But that's not the real problem. It would appear that the tried and trusted rules don't work for ID numbers of people born after 1/1/2000. I tried a few permutations but it doesn't seem straightforward. Any ideas? Also let me know if you want a copy of the old SQL - still have that.
Left by David on Dec 17, 2007 4:54 AM

# re: How to validate SA Identity Numbers
OK so I found the problem with my logic. Let me know if you want the old SQL code - it's here if you need it.
Left by David on Dec 18, 2007 9:00 AM

# re: How to validate SA Identity Numbers
Hi There everyone...
I must say that this is a very helpful for us.
Can i Push the limits and ask if there is any way
that you can validate a Passport number also?

Thank you.

Left by Gremlin1708 on Jan 28, 2008 2:04 AM

# re: How to validate SA Identity Numbers
Hi All,
I had the following ID validation done by a student programmer for a specific form page, how can I add/change this ID validation to the validation.js file so that it works on ALL other forms needing the SA ID number?
Regards
Jan

['validate-id', 'You have entered an invalid identity number', function (v) {
if (document.Doves.gender[0].checked)
return !Validation.get('IsEmpty').test(v) && /^([0-9]{2})(((0[13578])|(1[02]))((0[1-9])|([12][0-9])|(3[01]))|((0[469])|(11))((0[1-9])|([12][0-9])|(30))|(02)((0[1-9])|([12][0-9])))([5-9])([0-9]{3})([01])([0-9]{2})\$/.test(v) && ((document.Doves.date_of_birth.value.substring(2,4) == document.Doves.id_number.value.substring(0,2)) && (document.Doves.date_of_birth.value.substring(5,7) == document.Doves.id_number.value.substring(2,4)) && (document.Doves.date_of_birth.value.substring(8,10) == document.Doves.id_number.value.substring(4,6)))
else
return !Validation.get('IsEmpty').test(v) && /^([0-9]{2})((0[13578])((0[1-9])|([12][0-9])|(3[01]))|(0[469])((0[1-9])|([12][0-9])|(30))|(02)((0[1-9])|([12][0-9])))([0-4])([0-9]{3})([01])([0-9]{2})\$/.test(v) && ((document.Doves.date_of_birth.value.substring(2,4) == document.Doves.id_number.value.substring(0,2)) && (document.Doves.date_of_birth.value.substring(5,7) == document.Doves.id_number.value.substring(2,4)) && (document.Doves.date_of_birth.value.substring(8,10) == document.Doves.id_number.value.substring(4,6)))
}]
Left by Jan Kruger on Apr 26, 2008 2:09 AM

Hi, please can someone help with out with this problem:

The second last digit in my driver's licence is DIFFERENT to that in my green ID book. For example, the last three digits in my driver's licence is 050 --- but in my ID it is 084

This causes endless confusion.

One explanation might be that that the last THREE digits indicated race group in the old days and was done away with after the ANC came to power.
Left by Joe Jameson on May 07, 2008 11:15 AM

# re: How to validate SA Identity Numbers
Can anyone tell me how I can verify an S.A. Id # to the picture and name of the person on it so I know if the person I am dealing with is legitimate or just using an valid ID # with his picture on it . Thanks for any help
Left by Terrie on May 23, 2008 3:26 PM

# re: How to validate SA Identity Numbers wheather is married or not
I like this site it's usefull ,thank
Left by Boh on Jun 11, 2008 8:29 AM

# re: How to validate SA Identity Numbers
Hi,
could anyone help me with a procedure to calculate the validity of ID numbers in an MS-ACCESS database, returning invalid IDs?
Thank you
Left by Errol on Jun 27, 2008 3:03 AM

# re: How to validate SA Identity Numbers
To check on the status of your application for ID and/or Passport, please click on:

http://www.dha.gov.za/enquiry/get_status.asp

Cheers.

PS: You can also verify your Status
Left by Home Affairs Agent (MTM) on Jul 20, 2008 12:56 PM

# re: How to validate SA Identity Numbers
This is a great tool, thanks. Why is it that the last three digits of my ID number were changed - I think it was in the 1994 elections - from 007 to 080?
Left by Ian Steadman on Jul 23, 2008 8:05 AM

# re: How to validate SA Identity Numbers
pre 94 the 2nd&3rd last digits indicated race, with 00 being white, etc. My original ID book is long gone, so I do not have the full list anymore :)
Left by Joe on Jul 31, 2008 6:32 AM

# re: renewal off passport
I requested a renewal for a passport in March. My husband received his two months ago and I am still waiting. Please could you let me know the status of mine. ID 6904100087087.
Left by Tanya Muller on Aug 08, 2008 1:24 AM

# re: How to validate SA Identity Numbers
This is really useful. I'm trying to convert Craig Peacocks SQL version to PL/SQL function and not getting anywhere. Seems to return false all the time. Anybody out there able to help pls?

Here's my code:

CREATE OR REPLACE FUNCTION CS_VALID_SA_ID_NUMBER
( p_id_number IN VARCHAR2
)
RETURN BOOLEAN
AS

lv_A NUMBER := 0; -- ~Holds Negative Index numbers
lv_B NUMBER := 0; -- ~Holds Positive Index numbers
lv_C NUMBER;

lv_D NUMBER := -1; -- ~The check digit
lv_I NUMBER; -- ~Counter Variable
lv_is_valid NUMBER;
lv_the_number NUMBER;
lv_rply BOOLEAN := FALSE;

BEGIN

--Getting Negative Numbers
lv_I := 0 ;

IF (lv_I < 6) THEN
lv_A := lv_A + CAST(SUBSTR(p_id_number, 2 * lv_I + 1, 1) AS NUMBER);
lv_I := lv_I + 1;
END IF;

--Getting Positive Numbers
lv_I := 1;

IF (lv_I < 7) THEN

lv_B := (lv_B * 10) + CAST(SUBSTR(p_id_number, 2 * lv_I, 1) AS NUMBER);
lv_I := lv_I + 1;

END IF;

lv_B := lv_B * 2;
lv_C := 0;

IF (lv_B > 0) THEN lv_C := lv_C + lv_B mod 10;
lv_B := lv_B / 10;

END IF;

lv_C := lv_C + lv_A;
lv_D := 10 - (lv_C mod 10);

IF (lv_D = 10) THEN lv_D := 0;
END IF;

lv_the_number := CAST(SUBSTR(p_id_number, 13, 1) AS NUMBER);
IF lv_the_number = lv_D THEN
lv_is_valid := 1;
lv_rply := TRUE;
END IF;

RETURN lv_rply;

-- ************************************
-- ** Handle an unexpected exception **
-- ************************************
EXCEPTION
/* When this function throws an exception
outside its exception block via the exception
procedure will it catch its own exception. To avaoid
this the following statement is required.
*/
WHEN no_data_found THEN
lv_rply := FALSE;
return lv_rply;
WHEN OTHERS THEN
cs_raise_exception(SQLCODE, SQLERRM, 'CS_VALID_SA_ID_NUMBER');
END;

Left by Donal on Aug 13, 2008 4:31 AM

# re: How to validate SA Identity Numbers
OK, I've seen the errors of my ways and got it to work! (Thanks Craig Peacock for your T-SQL). Here's the Oracle PL/SQL code:

CREATE OR REPLACE FUNCTION FN_VALID_SA_ID_NUMBER
( p_id_number IN VARCHAR2
)
RETURN BOOLEAN
AS

/* =====================================================================
This function was adapted from a TSQL function written by Craig Peacock on
http://geekswithblogs.net/willemf/archive/2005/10/30/58561.aspx
Date: 2008/08/12

Description
-----------
Validates an SA ID number. (Returns 1=valid; 0=invalid)

=====================================================================
*/
lv_A NUMBER := 0; -- Holds Negative Index numbers (in odd number position)
lv_B VARCHAR2(7) := null; -- Holds Positive Index numbers (in even number position)
lv_B_num number(8,0) := 0; -- Holds Positive Index numbers
lv_C NUMBER;

lv_D NUMBER := -1; -- ~The check digit variable
lv_I NUMBER; -- Counter Variable
lv_dob NUMBER;
lv_valid_dob BOOLEAN := FALSE;
lv_is_valid NUMBER;
lv_last_number NUMBER;
lv_rply BOOLEAN := FALSE;
lv_length NUMBER;
lv_length_err EXCEPTION;

BEGIN
-- check length not <> 13
lv_length := LENGTH(p_id_number);
IF lv_length <> 13 THEN
lv_is_valid := 0;
RAISE lv_length_err ;
--RETURN lv_rply;
END IF;

-- check if first 6 digits are valid date (not strictly speaking necessary)
lv_dob := substr(p_id_number,0,6);
IF lv_dob IS NOT NULL AND to_date(lv_dob,'YYMMDD') IS NOT NULL THEN
lv_valid_dob := TRUE;
ELSE RETURN lv_rply;
END IF;

lv_I := 0 ;

-- adding every odd position digit (starting pos 1)(result goes into lv_A)
WHILE (lv_I < 6) LOOP
lv_A := lv_A + to_number(SUBSTR(p_id_number, 2 * lv_I + 1, 1));
lv_I := lv_I + 1;
END LOOP;

lv_I := 1;

-- Concatenating every even position digit (starting pos 2)
WHILE (lv_I < 7) LOOP
lv_B := lv_B || SUBSTR(p_id_number, 2 * lv_I, 1);
lv_I := lv_I + 1;

END LOOP;

-- multiply Concatenated number by two
lv_B_num := to_number(lv_B) * 2;

lv_C := 0;

-- Add up all the digits of the result in lv_B_num (result goes into lv_C)
WHILE (lv_B_num > 0) LOOP
lv_C := lv_C + lv_B_num mod 10;
lv_B_num := FLOOR(lv_B_num / 10);-- have to use FLOOR function here to prevent MOD function from rounding.

END LOOP;

/*WHILE (lv_B_num > 0) LOOP
lv_C := lv_C + lv_B_num mod 10;
lv_B_num := ROUND(lv_B_num / 10);

END LOOP; --WHILE
*/

-- Subtract the second digit (e.g. 3) from 10. The number must tally with the last number in the ID Number.
-- If the result is 2 digits, the last digit is used to compare against the last number in the ID Number.
-- If the answer differs, the ID number is invalid.
lv_C := lv_C + lv_A;
lv_D := 10 - (lv_C mod 10);

IF (lv_D = 10) THEN lv_D := 0;
END IF;

-- compare value in lv_D with lv_last_number
lv_last_number := CAST(SUBSTR(p_id_number, 13, 1) AS NUMBER);
IF (lv_last_number = lv_D) THEN
lv_is_valid := 1;
lv_rply := TRUE;
END IF;

RETURN lv_rply;

-- ************************************
-- ** Handle an unexpected exception **
-- ************************************
EXCEPTION
WHEN lv_length_err THEN
lv_rply := FALSE;
return lv_rply;
WHEN no_data_found THEN
lv_rply := FALSE;
return lv_rply;
--custom exception (place your own methods here)
--WHEN OTHERS THEN
-- raise_exception(SQLCODE, SQLERRM, 'FN_VALID_SA_ID_NUMBER');
END;
Left by Donal on Aug 18, 2008 3:24 AM

# re: How to validate SA Identity Numbers
Hi,

I need to find my fathers ID number as he has passed away but i have NO details about him, Is there anyway i could get that ?

Many thanks

Marc
Left by Marc Nothnagel on Aug 20, 2008 1:05 PM

# re: How to validate SA Identity Numbers
Hi there

I am a technical consultant and would like to know what the SSS as well as the A (8 & 9 in the id) and the z stands for.

Please also confirm whether the the intelligence built in the South African Id number remains the same!!!!

Regards;
candice
Left by Candice on Sep 08, 2008 9:43 AM

# re: How to validate SA Identity Numbers
thank you the information was very useful
Left by Colile on Sep 11, 2008 9:13 AM

# re: How to validate SA Identity Numbers
why? is it possible for people to make fake id numbers?
Left by Sibusiso on Sep 18, 2008 4:37 AM

# re: How to validate SA Identity Numbers
Java Implementation:

long oddNumberSum = 0;
long evenNums = 0;
//Getting the sum of odd numbers excluding the last digit
for(int i = 0; i < idnumber.length() - 1; i+=2){
oddNumberSum+= Long.parseLong(String.valueOf(idnumber.charAt(i)));
}

//Getting all the even numbers
StringBuilder evenNumsStr = new StringBuilder();
for(int i = 1; i < idnumber.length(); i+=2){
evenNumsStr.append(idnumber.charAt(i));
}

evenNums = Long.parseLong(evenNumsStr.toString().trim());

long dblEvenNums = evenNums * 2;

long dblEvensSum = 0;
for(int i = 0; i < String.valueOf(dblEvenNums).length(); i++){
dblEvensSum += Long.parseLong(String.valueOf(String.valueOf(dblEvenNums).charAt(i)));
}

long oddsPlusDblEvens = oddNumberSum + dblEvensSum;

long controlDigitCheck = 10 - Long.parseLong(String.valueOf(oddsPlusDblEvens).substring(String.valueOf(oddsPlusDblEvens).length() - 1));

if(controlDigitCheck == 10){
controlDigitCheck = 0;
}

if(controlDigitCheck != Long.parseLong(idnumber.substring(idnumber.length() - 1))){
return false;
}
else{
return true;
}
Left by Fana Sithole on Oct 27, 2008 5:27 AM

# re: How to validate SA Identity Numbers
Can you please email me a code that checks the 7th digit in RSA`s id numbers and determines the gender in VB.net
Left by zikona on Dec 03, 2008 3:12 AM

# re: How to validate SA Identity Numbers
Zikona...
Use http://www.carlosag.net/Tools/CodeTranslator/ to convert your code from c# to Vb.Net

You can even convert a section not the whole Method
Left by Musa on Dec 03, 2008 4:29 AM

# re: How to validate SA Identity Numbers
WHAT DOES THE 'A' and 'Z' (last 2 digits) stand for?
Left by Martine Jackson on Jan 16, 2009 2:35 AM

# re: How to validate SA Identity Numbers
More javascript if anyone cares. Only tested in firefox.

function validateID(idnum) {
idnum = idnum.toString().replace(" ","");
r = /^\d{10}[0-1]\d{2}\$/;
if (! r.test(idnum)) return false;
n = idnum;
p1 = parseInt(n[0]) + parseInt(n[2]) + parseInt(n[4]) + parseInt(n[6]) + parseInt(n[8]) + parseInt(n[10]);
p2 = (parseInt(n[1] + n[3] + n[5] + n[7] + n[9] + n[11]) * 2).toString();
p3 = 0;
for (i=0; i < p2.length; i++) {
p3+= parseInt(p2[i]);
}
check = 10 - (p1 + p3).toString()[(p1 + p3).toString().length -1];
check_char = check > 9 ? check.toString()[1] : check.toString();
if (check_char != idnum[12]) return false;
return true;
}

Left by Jasper on Feb 05, 2009 1:51 AM

# re: How to validate SA Identity Numbers
am a south african citizen but i lost my parents,pls smone could help me to get an id
Left by prince tj on Feb 13, 2009 2:20 AM

# re: How to validate SA Identity Numbers
Hi Benny, where does the Java code break?
Left by Fana Sithole on Feb 23, 2009 1:55 AM

# re: How to validate SA Identity Numbers
Nice site!

How 'bout a Java version from somebody who has made it word?
Left by Maxi on Mar 05, 2009 3:05 AM

# re: How to validate SA Identity Numbers
private static int testIdStr(String ids){
int a=0;
for (int i=0;i<12;i+=2){
a+=Integer.parseInt(ids.charAt(i)+"");
}
String bStr="";
int b=0;
for (int i=1;i<12;i+=2){
bStr+=ids.charAt(i);
}
b=Integer.parseInt(bStr);
b*=2;
int d;
int c = 0;
do
{
c += b % 10;
b = b / 10;
}
while(b > 0);
c += a;
d = 10 - (c % 10);
if(d == 10) d = 0;
return d;
}

Takes the ID number as a string parameter, returns the control digit as an integer. I've not added any error checking, so add that as needed. :)
Left by James on Mar 22, 2009 12:18 PM

# re: How to validate SA Identity Numbers
WOW!
This blog ran from 2006 and is still active...
When something's good, the thing's good...
Thanks guys, this is helping a lot of us...
Left by Shepard Sithole on Mar 25, 2009 5:09 AM

# re: How to validate SA Identity Numbers
Hi guys, well here is an updated piece of code in VB be it VB.NET, VB6, MS ACCESS OR ASP. I added a couple of my own checks for certain errors like the idnumber 0000000000000 or 6666666666666 which is also verified as valid. Erm. And then what if dates are incorrect aswell. Please note that no Y2K Leapyear cheacks are performed.

Function CheckIDNumber(ByVal sIDNommer)
If sIDNommer = "1111111111111" Or sIDNommer = "6666666666666" Then
Return False
Exit Function
Else
If sIDNommer.ToString.Substring(2, 2) > 12 Or sIDNommer.ToString.Substring(4, 2) > 31 Then
Return False
Exit Function
Else
If sIDNommer.ToString.Substring(2, 2) = 2 And sIDNommer.ToString.Substring(4, 2) > 29 Then
Return False
Exit Function
Else
End If
End If
End If
Dim idNo
Dim a As Integer = 0
Dim b As Integer = 0
Dim c As Integer = 0
Dim d As Integer = -1
Dim sIDNom As String = ""
Dim iVal As Integer = 0
If Len(sIDNommer) <> 13 Then
CheckIDNumber = False
Else
For i = 1 To Len(sIDNommer)
sIDNom = sIDNom & Mid(sIDNommer, i, 1) & ":"
Next
idNo = Split(sIDNom, ":")

For i = 0 To 5
iVal = i * 2
On Error Resume Next
a = a + CInt(idNo(iVal))
Next
b = 0
For i = 0 To 5
iVal = 2 * i + 1
b = b * 10 + CInt(idNo(iVal))
Next

b = b * 2
c = 0
Do
c = c + (b Mod 10)
b = Fix(b / 10)
Loop While b > 0
c = c + a
d = 10 - (c Mod 10)
If (d = 10) Then d = 0
CheckIDNumber = d
If d = CInt(idNo(12)) Then
CheckIDNumber = True
Else
CheckIDNumber = False
End If
End If
End Function
Left by Jaco on Apr 07, 2009 8:08 AM

# re: How can i watch my id photo
my photo
Left by steven phaswane on Apr 23, 2009 12:28 PM

# this rocks
thanks, I am so glad this blog is here - just made my life a lot easier..
Why does this sort of information have to be provided by Joe public? must be a big secret..
Left by simon on Apr 25, 2009 10:11 AM

# fix for Jasper's function
the javascript function Jasper posted is great (short and sweet) and I have adopted it, but found it fails on an idnumber which has 0 for a second digit, have modified it to use the radix arg to force it to use hexadecimal and now it works fine.

function validateID (idnum) {
idnum = idnum.toString().replace(" ","");
r = /^\d{10}[0-1]\d{2}\$/;
if (idnum == '0000000000000') return false;
if (! r.test(idnum)) return false;
n = idnum;
p1 = parseInt(n[0],10) + parseInt(n[2],10) + parseInt(n[4],10) + parseInt(n[6],10) + parseInt(n[8],10) + parseInt(n[10],10);
p2 = (parseInt(n[1] + n[3] + n[5] + n[7] + n[9] + n[11],10) * 2).toString();
p3 = 0;
for (i=0; i < p2.length; i++) {
p3+= parseInt(p2[i]);
}
check = 10 - (p1 + p3).toString()[(p1 + p3).toString().length -1];
check_char = check > 9 ? check.toString()[1] : check.toString();
if (check_char != idnum[12]) return false;
return true;
}
Left by simon on Apr 28, 2009 5:09 AM

# cumulative C# Id Check code
This is a cumulative C# code (DotNet 2) update of the above postings. Has anyone seen an id number of a person born in 2000 or 2001? How is the year displayed?

private static bool IdNo_IsValid(String ids)
{

bool valid = false;
int a = 0;
int b = 0;
int d;
int c = 0;
int s = ids.Length;
String bStr = "";

if ((s == 13) & (ids != "0000000000000") & (ids != "6666666666666"))
{

for (int i = 0; i < 12; i += 2)
{
a += int.Parse(ids.Substring(i, 1) + "");
}

for (int i = 1; i < 12; i += 2)
{
bStr += ids.Substring(i, 1);
}

b = int.Parse(bStr);

b *= 2;

do
{
c += b % 10;
b = b / 10;
}
while (b > 0);

c += a;

d = 10 - (c % 10);

if (d == 10) d = 0;

if (Convert.ToInt16(ids.Substring(s - 1, 1)) == d)
{
valid = true;
}

}

return valid;

}

Left by Rob on May 20, 2009 3:36 AM

# re: How to validate SA Identity Numbers
HI all this is indeed a great site. is there anyone with any ideas on how to check if a drivers licence is issued(without running into a road block that is)
Left by rocky on Jul 23, 2009 8:55 AM

# re: How to validate SA Identity Numbers
hi,i would like to check whether my fiancee has been married before,i only have his name and surname.
Left by asanda on Aug 06, 2009 7:31 AM

# re: How to validate SA Identity Numbers
Is there anyway that you identify race by and id number? If anyone can help me please send me a mail I would really appreciate it very much.
Left by Les Williams on Aug 13, 2009 8:54 AM

# re: How to validate SA Identity Numbers
Is there anyway that you identify race by and id number? If anyone can help me please send me a mail at les@cellcconnect.co.za. I would really appreciate it very much
Left by Les Williams on Aug 13, 2009 8:57 AM

# re: How to validate SA Identity Numbers
How can I Validate SA Identity Numbers In VB for Begginers
Left by Stanley on Sep 21, 2009 10:17 AM

# re: How to validate SA Identity Numbers
Hi Stanley - VB.NET code is further up in this post:

http://geekswithblogs.net/willemf/archive/2005/10/30/58561.aspx#118884
Left by Willem on Sep 22, 2009 12:43 AM

# re: How to validate SA Identity Numbers
is it at all possible for me to have my names and surname changed on my ID. If so, dos my ID NUmber change.
Left by naseema on Sep 22, 2009 6:47 AM

# re: How to validate SA Identity Numbers
Hi,

I was wondering if anyone could help me by telling me where to put the vb.net code for ID validation.

Thank you
Left by Mistery1 on Sep 29, 2009 7:36 AM

# re: How to validate SA Identity Numbers
How to check if i am not married cause i lost my identity document
Left by Dorcas on Nov 21, 2009 9:09 AM

# re: How to validate SA Identity Numbers
I no it is out the line. but i only want to find out about how can prove the child surname is being change to the father.
Left by DAVID SEEKOEI on Nov 23, 2009 12:42 AM

# re: How to validate SA Identity Numbers
how do i catch an ID exception in java?
Left by precious on Nov 28, 2009 5:13 PM

# re: How to validate SA Identity Numbers
Hi could someone help me find out what my ID number was i have lost all paperwork and want to come back to SA
Left by Gerry on Jan 20, 2010 4:59 AM

# re: How to validate SA Identity Numbers
Is it possible to have duplicate ID numbers and under what conditions so I can build the validations?
Left by wilma on Jan 20, 2010 2:46 PM

# re: How to validate SA Identity Numbers
Wilma, no, in a perfect world there is no chance of duplicate id's - that's the reason for the DOB/G sequence - if a person of the same gender is born on the same day the sequence number is advanced to the next available number - obviously that will also change the value of the check digit. In reality, it has been found that DHA has released valid and active duplicate id's - so it is possible to get multiple duplicate id's. This rare - in any case there is no way you can check this, other than have your app. flag it if it occurs, I suppose.
Left by Willem on Jan 20, 2010 11:58 PM

# re: How to validate SA Identity Numbers
id number blocked
Left by lucy on Jan 21, 2010 7:10 AM

# re: How to validate SA Identity Numbers
Hi all
am developing a CRM call center system how can i have a validate user ID by referencing @ their gender and date of birth
Left by Crazy 8 on Mar 12, 2010 4:22 AM

# How to validate SA Identity 6606166651081 2000+2010
plz ripot
Left by yusuf on Apr 18, 2010 5:03 AM

# re: How to validate SA Identity Numbers
How to validate SA Identity Numbers 6606166651081
Left by yusuf on Apr 18, 2010 5:14 AM

# re: How to validate SA Identity Numbers
How to validate SA Identity2000+2010
Left by yusuf on Apr 18, 2010 5:14 AM

# re: How to validate SA Identity Numbers
how do i catch an ID exception in now
Left by yusuf on Apr 18, 2010 5:16 AM

# re: How to validate SA Identity Numbers
how do i catch an ID exception in java?

Left by yusuf on Apr 18, 2010 5:18 AM

# re: How to validate SA Identity Numbers
I have a problem with my id 641103 0636 081. when my passport expired in 2007, i tried applying for another one but the home affairs could not help me as someone else is using my is number. i urgently need to go to Beijin and in need of a new passport. i need at least a temporary passport for this.
Left by MPHO MODISE on May 03, 2010 8:13 AM

# re: How to validate SA Identity Numbers
Does the validation work for non SA Citizens with a green bar coded ID Document or is there a different formula as I have a non citizen with and ID Number that verified of Dept of Home Affairs website but invalid with formula for validation
Left by S Chetty on May 05, 2010 2:32 AM

# re: How to validate SA Identity Numbers
dear
i lost my south african id
i need to know how can i get it back
7804126195187 this is my id no
Left by adam on May 26, 2010 7:23 AM

# re: How to validate SA Identity Numbers
Hi, i am sharing my identity with someone else only our fingerprints differ. Im about to get married and i can't because of that. Please help
Left by maggie ngobeni on Jun 18, 2010 2:56 AM

# re: How to validate SA Identity Numbers
exactly how can I validate id numbers?
Left by Radebe on Jun 28, 2010 11:45 AM

# re: How to validate SA Identity Numbers
As I understand from the description, this should work... Anyone care to check it?

\$id="*****SA ID*****";
\$odd=\$id['0']+\$id['2']+\$id['4']+\$id['6']+\$id['8'];
\$even_sum=\$id['1'].\$id['3'].\$id['5'].\$id['7'].\$id['9'].\$id['11'];
\$even=\$even_sum*2;
\$even=\$even."";
\$temp=0;
\$i=0;
echo \$even."<br/>";
while(\$i < (strlen(\$even))){
\$temp=\$temp+\$even[\$i];
\$i++;
}
\$even=\$temp;
\$total=\$odd+\$even;
\$total=\$total."";
if(\$total[1]>0){
\$test=10-\$total[1];
}else{\$test=0;}
if(\$test==\$id[12]){
echo "Valid Id";
} else {
echo "Invalid Id";
}
Left by Lionel on Jul 03, 2010 9:11 PM

# re: How to validate SA Identity Numbers
I want to apply for a homeloan , but when they check my id number it shows that my ID number belongs to a woman

I need to find out how could a female and a male share the same identity number?

We all know that female ID numbers start with the number 0 after date of birth and the male ID numbers start with the number 5.

This is a worrying situation, what can I do?????????

Left by Sarel on Jul 21, 2010 11:05 AM

# re: How to validate SA Identity Numbers
Python Script:

def validateID(IDNum):
"""Validates a South African ID Number"""
if len(IDNum) != 13:
return False
if IDNum[10] > 1:
return False
d = -1
a = 0
for i in range(0,6):
a += int(IDNum[2*i])
b = 0
for i in range(0,6):
b = b * 10 + int(IDNum[2*i+1])
b *= 2
c = 0
while b > 0:
c += b % 10
b = b / 10
c += a
d = 10 - (c % 10)
if d == 10:
d = 0
return(str(d) == IDNum[12])
Left by Justin Unwin on Jul 26, 2010 3:01 AM

# re: How to validate SA Identity Numbers
So if some males and females share the same ID number even though the gender for female is 0 - 4 and male 5 - 9 is it posible for a female then to have for example a 5 for her gender digit
Left by Leon on Aug 11, 2010 2:07 AM

# re: How to validate SA Identity Numbers
Hi guys here is the C code version.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static short checkDigit(const char *q)
{
short sRetCode = 0;
unsigned char c;

while (*q)
{
c = *q;
sRetCode = isdigit(c);
if (sRetCode == 0)
break;
q++;
}

return sRetCode;
}

static short CheckForValidID(const char *ID)
{
short sRetCode = 1, i = 0;
char TempArr1[8];
char TempArr2[8];
long lResult1 = 0;
long lResult2 = 0;
long lResult = 0;
short CheckDigit = 0;
const char *p = NULL;

memset(TempArr1,0x00,strlen(TempArr1));
memset(TempArr2,0x00,strlen(TempArr2));

p = ID;

if (strlen(ID) != (size_t) 13) /* Check if ID length is equal to 13 characters. */
return 0;

if (checkDigit(ID) == 0) /* Check if ID is all digits. No alphanumeric values allowed. */
return 0;

for (i = 0;i < 6;i++)
{
ID = p +(2*i);
TempArr1[i] = *ID;
lResult1 = lResult1 + (long)atoi(&TempArr1[i]);
}

for (i = 0;i < 6;i++)
{
ID = p + ((2*i) + 1);
TempArr2[i] = *ID;
}

lResult2 = 2 *(atoi(TempArr2));

lResult = lResult1;

while (lResult2 > 0)
{
lResult += (lResult2 % 10);
lResult2 = lResult2 / 10;
}

CheckDigit = 10 - (lResult % 10);

if (CheckDigit == 10)
CheckDigit = 0;

ID = (p + 12);
if (CheckDigit == atoi(ID))
sRetCode = 1;
else
sRetCode = 0;

return sRetCode;
}
Left by Donald Asante on Sep 13, 2010 11:50 AM

# re: How to validate SA Identity Numbers
-- =============================================
ALTER FUNCTION [dbo].[CheckSumID]
(
@id nvarchar(13)
)
RETURNS integer
AS
BEGIN
DECLARE @Result integer = 0, @rem integer = 0, @odd integer = 0,
@i integer = 12, @even integer = 0

IF (@id IS NOT NULL) AND (LEN(@id) = 13) AND (ISNUMERIC(@id) = 1)
BEGIN
WHILE @i > 0
BEGIN
IF (@i % 2) = 0
BEGIN
SELECT @even = @even + @rem + ((CONVERT(integer, SUBSTRING(@id, @i, 1)) * 2) % 10)
SELECT @rem = (CONVERT(integer, SUBSTRING(@id, @i, 1)) * 2) / 10
END ELSE SELECT @odd = @odd + CONVERT(integer, SUBSTRING(@id, @i, 1))
SELECT @i = @i - 1
END
SELECT @Result = 10 - ((@even + @odd + @rem) % 10)
END ELSE SELECT @Result = NULL
RETURN @Result
END
Left by kb on Sep 22, 2010 2:22 PM

# re: How to validate SA Identity Numbers
Here's my validation method, in Ruby:
----
SA_ID_REGEX = /^(\d{2})(\d{2})(\d{2})(\d{1})\d{3}(\d{1})\d{1}(\d{1})\$/

def validate(id)
id = id.to_s.gsub(/\s/, "") # Convert to String, strip out all whitespace
return false unless id =~ SA_ID_REGEX

a = 0 # Add all the digits in the odd positions.
b = 0 # Stack the even positions and multiply by 2.
0.upto(5) do |i|
a += id[2*i].chr.to_i
b = b*10 + id[2*i + 1].chr.to_i
end
b = b*2

c = 0
while b > 0
c += b % 10
b = b / 10
end
c += a
d = (10 - (c % 10)) % 10 # Subtract second digit from 10. If result is 2 digits, use last digit.

id.scan(SA_ID_REGEX) do |yy, mm, dd, gender, citizen, control|
# Do other stuff here with date of birth, etc. if you like
return (d == control.to_i)
end
end
----

I also did a purely Integer-based calculation (with lots of modulus) but it came out slower on the benchmark strangely, even though this method includes regex matching. If you're interested, it was based around this function:

class Integer
def pos(n) # get the digit at position (n), starting from the back
(self % (10 ** n)) / (10 ** (n-1))
end
end

Oh, and lastly, @Sarel (7/21/2010 11:05 AM): Get a sex change. ;)
Left by Dave on Sep 27, 2010 7:43 AM

# re: How to validate SA Identity Numbers
Just because a buddy required a javascript version, here it is...syntactically virtually the same...

<Script LANGUAGE="JavaScript">

function GetControlDigit(ParsedIdString)
{

var d = -1;
var a = 0;

for(var i = 0; i < 6; i++)
{
a += parseInt(ParsedIdString.substring(2*i,2*i+1));
}

var b = 0;
for(var i = 0; i < 6; i++)
{
b = b*10 + parseInt(ParsedIdString.substring(2*i+1,2*i+1+1));
}

b *= 2;
var c = 0;

do{
c += parseInt(b) % 10;
b = parseInt(b) / 10;
}while(b > 0);

c += parseInt(a);
d = 10 - (parseInt(c) % parseInt(10));
if(d == 10) d = 0;

return d;
}
</script>
Left by GDR on Oct 07, 2010 5:19 AM

# re: How to validate SA Identity Numbers
And now that I've done that, I read the rest of the posts and find a few javascript versions in here already...ummm..dumb-ass
Left by GDR on Oct 07, 2010 5:30 AM

# re: How to validate SA Identity Numbers
Interesting ... very very interesting...
FYI .. a bit of useless information:
All functions should check if the Date of birth is correct!!!
I repeat: Check if the date of birth exists otherwise you will get a few that validate even if they aren't valid ...
Have created a SQL function similar to these on this site ... Working on a database of over 10 million ID numbers so please check the date of birth is valid:
i.e. 200231******* will validate but the date of birth is incorrect .. there is not 31 days in February.
(Yep when I tried to derive the age of a few I got a few more that was now invalid on a legacy system, so please validate with a date of birth check first ... )

My two cents
Left by Converting ID dumbass on Oct 15, 2010 10:47 AM

# re: How to validate SA Identity Numbers
Last in South Africa in 1982, lost mt ID number, been told it is almost impossible to prove who i am, how can i try and work out my ID no.
Left by Rod Sheridan on Oct 18, 2010 8:39 AM

# re: How to validate SA Identity Numbers
This is all very cool, but does anyone know how to do this in DBASE?
Left by Vicus on Nov 11, 2010 6:48 AM

# re: How to validate SA Identity Numbers
plz my id south african no.6606166651081 so plz check and my mail reply thx
Left by mohamad on Nov 17, 2010 12:05 AM

# re: How to validate SA Identity Numbers
you can also have a look here for a good explanation: http://www.polemus.net/2011/01/getting-information-from-south-african.html
Left by Dusty Roberts on Jan 07, 2011 3:53 AM

# re: How to validate SA Identity Numbers
Thanks for all the help!! Made life so much easier!!
Left by Ewald on Jan 09, 2011 10:57 AM

# re: How to validate SA Identity Numbers
Please can you advise me how to get my fathers ID number. He passed away in 1981. I have an ID number for my mother who passed away in 1974. I am trying to get a copy of their marriage certificate but when checking using my mothers id it says her status is single.I thought if I found my fathers id number I could see if that one will bring up his status as married. They definitely married in johannesburg in 1950.

I am also looking for passport details etc for myself born 1953, my mother born 1929 and my father a south african citizen but born in Lithuania.

Can you help me or lead me in the right direction.
Left by sharon shapiro on Mar 31, 2011 4:44 AM

# Passport
Please can you refer me to the right person working with passport in SA.I'm from Namibia and applied for my daughter's passport,her finger prints was problem,last year ocktober the new finger prints was send to SA,but til now,have not receive my daugters passport yet and did til now not land in Windhoek SA High commission,i need passport urgent!!

Thank You
Left by Elrika Kruger on Apr 07, 2011 9:14 AM

# How to validate SA Identity Numbers details
I want to know if this Identity is true to the best of your knowledge, Because they are presented to me for credit in advance. please help .
Left by mavundla j i on Apr 13, 2011 12:23 PM

# re: How to validate SA Identity Numbers
need my id number
Left by Ellen Christodoulakis on Apr 13, 2011 3:08 PM

# re: How to validate SA Identity Numbers
I recently got my vault birth certificate and I see that my biological dad and my mom had ID numbers that were different to the normal 13 digit ID's. Both their ID's were 9 digits long and didn't have the date of birth as the first 6 digits. He was born in 1946 in Rhodesia and she in 1951 in Durban. When did the ID numbers change and is there anyway of tracking his new ID number, using his old number?
Left by grant webb on Apr 23, 2011 5:30 AM

# re: How to validate SA Identity Numbers
how to i verify a date of issue of a id number
Left by mark on Apr 25, 2011 1:29 AM

# re: How to validate SA Identity Numbers
i want to getidentity namber
Left by aregawi yemane on Apr 29, 2011 2:37 AM

# re: How to validate SA Identity Numbers
Good day, i am looking for a site to do a full backround check on a woman, sa citizen. i have her ID number, it is valid, and looking from her work experience, any criminal record, current job placement to her car registration number.
Left by Lara strauss on Jun 08, 2011 11:19 AM

# re: How to validate SA Identity Numbers
how can i validate the passport number of other countries
?
Left by Vuyiswa on Jun 14, 2011 3:28 AM

# re: How to validate SA Identity Numbers
please can you check the following id number 6805190188082 and give me the status of this person (me) or my passport
Left by vanessa hartslief on Jun 27, 2011 9:55 AM

# re: How to validate SA Identity Numbers
Hallo

How will I validate Namibian Id numbers

Thanks
Left by Eugene on Jul 15, 2011 1:50 AM

# re: How to validate SA Identity Numbers
I need an ID number to apply for a personal loan
Left by Pokhun Mookeshwar on Aug 15, 2011 7:41 AM

# How to validate SA Identity Numbers
I need to find out an old ID number (from the 60's). I have the present day ID number but need the old number from the old "ID Card". How do I do this?
Left by Diane Ching on Sep 05, 2011 9:35 AM

# re: How to validate SA Identity Numbers
Hi There, I am on the web searching for a way to find a persons contact number, I have limited information most of the time, normally just a full name, sometimes an ID number. Is there anyway to get this information legally but cheap. We are an organisation newly formed that try and help people who are loosing their homes at a sheriffs auction but the information we get is off the government gazette and its very limited. We have an address but it doesnt help much as we cant find the people sometimes at home or its in an estate or compex and its very difficult to be allowed access in. Hoping you could help somehow?
Left by joe on Sep 08, 2011 4:26 AM

# re: How to validate SA Identity Numbers in javascript
How to validate SA Identity Numbers in javascript with a form to help
Left by Preneshree on Nov 14, 2011 5:52 AM

# re: How to validate SA Identity Numbers
could you assist me with the name and surname of this ID NO 6003100700085
Left by SILINDA FRANK on Nov 15, 2011 7:20 AM

# re: How to validate SA Identity Numbers
Am the best
Left by Hangwi on Nov 24, 2011 2:11 PM

# re: How to validate SA Identity Numbers
For MS-Office you can use the following VBA code:

Function ID_Valid(ID As String) As String
'This algoritm test the validity of a South African ID number

Dim D(13, 2) As Integer, N As Integer, Check As String
'delete spaces
ID_Valid = Replace(ID, " ", "")

For N = 1 To 12
D(N, 1) = Val(Mid(ID_Valid, N, 1))
If N Mod 2 = 0 Then
D(N, 2) = D(N, 1) * 2
If D(N, 2) >= 10 Then
D(N, 2) = Int(D(N, 2) / 10) + (D(N, 2) - Int(D(N, 2) / 10) * 10)
End If
Else
D(N, 2) = D(N, 1)
End If
D(0, 0) = D(0, 0) + D(N, 2)
Next N
Check = CStr(D(0, 0) * 9)
Check = Right(Check, 1)
If Check = Right(ID_Valid, 1) Then
ID_Valid = "ID number OK"
Else
ID_Valid = "ID number Error"
End If
End Function
Left by Carlo Schots on Dec 20, 2011 4:20 AM

# re: How to validate SA Identity Numbers
my id number 6512185560081
i want to check if it is holding my name
Left by assaad safwan on Dec 24, 2011 11:52 AM

# re: How to validate SA Identity Numbers
Id number
Left by Ali Elcheikhmohamad on Dec 24, 2011 12:03 PM

# re: How to validate SA Identity Numbers
Could you please provide me with the name of this id number 0312160110085. Or advise me how I can find out if my son's estranged wife has changed the child's name?
Left by Valerie Breedt on Feb 11, 2012 5:16 AM

# re: How to validate SA Identity Numbers
i have lost my late mothers ID number how can I find it.
Left by Craig Gorman on Feb 22, 2012 8:07 AM

# re: How to validate SA Identity Numbers
DHA Accelerator
The requested URL could not be retrieved
While trying to retrieve the URL:
http://www.dha.gov.za/enquiry/marital/status/marital_status.asp

The following error was encountered:

Unable to forward this request at this time.
This request could not be forwarded to the origin server or to any
parent caches. The most likely cause for this error is that:

The cache administrator does not allow this cache to make
direct connections to origin servers.
All configured parent caches are currently unreachable.

Ek kan nie meer oopmaak om te sien of persoon volgens ID nommer getroud, geskei of enkellopend is nie, al wat ek kry is bostaande --------------------------------------------------------------------------------

Generated Thu, 08 Mar 2012 06:54:24 GMT by inv-proxy.dha.gov.za (squid)
Left by ARTHUR on Mar 08, 2012 12:59 AM

# re: How to validate SA Identity Numbers
For a Delphi function:

function Modules10SARSValidID(const ANumber: String): Boolean;
var
TotalStr: String;
TotalLength: Integer;
CheckDigit: Integer;
ANumberLength: Integer;
ErrMsg: String;
EvenString: String;
OddTotal, EvenTotal: Integer;
Total: Integer;
i, j: Integer;
begin
ErrMsg := '';

ValidateString(ANumber, vo_Numbers, '', ErrMsg);
Result := (ErrMsg = '');

if (Result) then begin
EvenString := '';
OddTotal := 0;
EvenTotal := 0;

for i := 1 to Length(ANumber) do begin
if (not (Odd(i))) then
EvenString := EvenString + ANumber[i]
else
if (i <> 13) then
OddTotal := OddTotal + StrToInt(ANumber[i]);
end;
if (EvenString > '') then
EvenTotal := (StrToInt(EvenString) * 2);
EvenString := FloatToStr(EvenTotal);
EvenTotal := 0;
for j := 1 to Length(EvenString) do begin
EvenTotal := EvenTotal + StrToInt(EvenString[j]);
end;

Total := OddTotal + EvenTotal;
TotalStr := IntToStr(Total);
TotalLength := Length(TotalStr);
CheckDigit := 10 - StrToInt(TotalStr[TotalLength]);
ANumberLength := Length(ANumber);

if (CheckDigit <> StrToInt(ANumber[ANumberLength])) then
Result := False;
end;
end;
Left by Bokkie on Mar 20, 2012 4:01 AM

# re: How to validate SA Identity Numbers
please explain this process to me it's not clear:

calculated as follows using ID Number 800101 5009 087 as an example:

Add all the digits in the odd positions (excluding last digit).
8 + 0 + 0 + 5 + 0 + 0 = 13...................[1]
====================================
Move the even positions into a field and multiply the number by 2.
011098 x 2 = 22196

here are suppose to add even numbers or odd? before we x by 2.
Left by Mabutho on Apr 20, 2012 7:44 AM

# re: How to validate SA Identity Numbers
Hi I would like to know if there is any way that you can check the citizenship using an ID number? The problem comes in where people become South African Citizens after being (for example) a Brittish citizen. Is a new ID number issued, or how does this work?

Kind regards
Anne
Left by Anne on Apr 23, 2012 6:16 AM

# re: How to validate SA Identity Numbers
Hi Anne.
I believe they'll just get a new ID number.
(which would be based on his birthdate, etc). Original citizenship doesn't matter in RSA id numbers as far as I know.
Left by Wimpie on Apr 30, 2012 11:11 AM

# re: How to validate SA Identity Numbers
Hi,can you please help me validate my I.D number because i dont know where and how to use the scripts provided,i tried and i faild please assist or should i provide you with my I.D number?im stranded...here is my email adress: mayken85@gmail.com
Left by Chris on May 04, 2012 3:43 AM

# re: How to validate SA Identity Numbers
I need to find somebody ASAP - ID NR: 3810220060080
Left by Etienne on May 11, 2012 1:24 AM

# re: How to validate SA Identity Numbers
i want to check my id number
Left by adele simpson on May 11, 2012 11:08 AM

# re: How to validate SA Identity Numbers
Hi, for those that want to check a SA ID number in Excel here is a working formula. Probable could be simpler but it works. This formula refers to cell A1.

=IF(RIGHT(A1,1)=(RIGHT(10-RIGHT((MID(A1,1,1)+MID(A1,3,1)+MID(A1,5,1)+MID(A1,7,1)+MID(A1,9,1)+MID(A1,11,1))+(IF(LEN(CONCATENATE(MID(A1,2,1),MID(A1,4,1),MID(A1,6,1),MID(A1,8,1),MID(A1,10,1),MID(A1,12,1))*2)=7,MID(CONCATENATE(MID(A1,2,1),MID(A1,4,1),MID(A1,6,1),MID(A1,8,1),MID(A1,10,1),MID(A1,12,1))*2,1,1)+MID(CONCATENATE(MID(A1,2,1),MID(A1,4,1),MID(A1,6,1),MID(A1,8,1),MID(A1,10,1),MID(A1,12,1))*2,2,1)+MID(CONCATENATE(MID(A1,2,1),MID(A1,4,1),MID(A1,6,1),MID(A1,8,1),MID(A1,10,1),MID(A1,12,1))*2,3,1)+MID(CONCATENATE(MID(A1,2,1),MID(A1,4,1),MID(A1,6,1),MID(A1,8,1),MID(A1,10,1),MID(A1,12,1))*2,4,1)+MID(CONCATENATE(MID(A1,2,1),MID(A1,4,1),MID(A1,6,1),MID(A1,8,1),MID(A1,10,1),MID(A1,12,1))*2,5,1)+MID(CONCATENATE(MID(A1,2,1),MID(A1,4,1),MID(A1,6,1),MID(A1,8,1),MID(A1,10,1),MID(A1,12,1))*2,6,1)+MID(CONCATENATE(MID(A1,2,1),MID(A1,4,1),MID(A1,6,1),MID(A1,8,1),MID(A1,10,1),MID(A1,12,1))*2,7,1),IF(LEN(CONCATENATE(MID(A1,2,1),MID(A1,4,1),MID(A1,6,1),MID(A1,8,1),MID(A1,10,1),MID(A1,12,1))*2)=6,MID(CONCATENATE(MID(A1,2,1),MID(A1,4,1),MID(A1,6,1),MID(A1,8,1),MID(A1,10,1),MID(A1,12,1))*2,1,1)+MID(CONCATENATE(MID(A1,2,1),MID(A1,4,1),MID(A1,6,1),MID(A1,8,1),MID(A1,10,1),MID(A1,12,1))*2,2,1)+MID(CONCATENATE(MID(A1,2,1),MID(A1,4,1),MID(A1,6,1),MID(A1,8,1),MID(A1,10,1),MID(A1,12,1))*2,3,1)+MID(CONCATENATE(MID(A1,2,1),MID(A1,4,1),MID(A1,6,1),MID(A1,8,1),MID(A1,10,1),MID(A1,12,1))*2,4,1)+MID(CONCATENATE(MID(A1,2,1),MID(A1,4,1),MID(A1,6,1),MID(A1,8,1),MID(A1,10,1),MID(A1,12,1))*2,5,1)+MID(CONCATENATE(MID(A1,2,1),MID(A1,4,1),MID(A1,6,1),MID(A1,8,1),MID(A1,10,1),MID(A1,12,1))*2,6,1),MID(CONCATENATE(MID(A1,2,1),MID(A1,4,1),MID(A1,6,1),MID(A1,8,1),MID(A1,10,1),MID(A1,12,1))*2,1,1)+MID(CONCATENATE(MID(A1,2,1),MID(A1,4,1),MID(A1,6,1),MID(A1,8,1),MID(A1,10,1),MID(A1,12,1))*2,2,1)+MID(CONCATENATE(MID(A1,2,1),MID(A1,4,1),MID(A1,6,1),MID(A1,8,1),MID(A1,10,1),MID(A1,12,1))*2,3,1)+MID(CONCATENATE(MID(A1,2,1),MID(A1,4,1),MID(A1,6,1),MID(A1,8,1),MID(A1,10,1),MID(A1,12,1))*2,4,1)+MID(CONCATENATE(MID(A1,2,1),MID(A1,4,1),MID(A1,6,1),MID(A1,8,1),MID(A1,10,1),MID(A1,12,1))*2,5,1)))),1),1)),"Valid","Invalid")
Left by Garreth on Jul 03, 2012 7:27 AM

# re: How to validate SA Identity Numbers
Thanks for a great post! Just as a matter of interest:

I had to construct an ID validator using VB in 2006 for an app being used at certain Department Of Health sites. During the process I managed to trace the son of the developer of the original algorithm for the Department Of Home Affairs (DOHA) who in turn explained the entire algorithm to me in detail. Subsequently my code worked perfectly and was tested extensively using both old and new ID numbers.

Not long after deployment a user submitted a copy of a “valid” ID which was reported by the system as an invalid ID number. Subsequently I took my code apart, but failed to find any problem with it. Eventually I approached DOHA and after hours of failed attempts (officials blatantly refused to discuss the problem) managed to get through to an official at management level who verbally confirmed that DOHA is aware of the fact that certain ID numbers were issued incorrectly due to 1) duplicated ID numbers being used and 2) an incorrect algorithm being used to generate ID numbers. So much for validating an ID number…

Still, it appears the most secure current solution. Always add additional code to validate the date of birth, which will eliminate problem strings such as “0000000000000” and “6666666666666”.
Left by yolandre on Jul 29, 2012 1:48 PM

# re: How to validate SA Identity Numbers
Please could you work my late mother in law's id number out. She was born in Cape Town on the 15th August 1908
I hope you can help.
many thanks
elsa
Left by elsa gomez on Aug 31, 2012 6:27 AM

# re: How to validate SA Identity Numbers
i have apley for sa id i check in computer is there is there in computer but i haven t got so how i can get plz tell me
Left by sa on Sep 20, 2012 3:13 PM

# re: How to validate SA Identity Numbers
Hi, I am searching for my late husband's ID number.
R.O.van Zyl
Birthdate; 29.04.1937
Died; 04.03.1980
Left by S.M.Coetzee on Oct 05, 2012 11:54 AM

# re: How to validate SA Identity Numbers
Hi,

Can you help me with code to validate Indian Passport number?

Thanks
Left by Anita on Feb 12, 2013 7:01 PM

# re: How to validate SA Identity Numbers
Could you please provide me with the name of this id number 880327 5416 088. Or advise me how I can find out ?
Left by Marijke on Feb 27, 2013 9:01 AM