CancelImage Upload

Republic of South Africa Identity Document Validation with Regular Expressions

At the age of 16 years, every citizen in the Republic of South Africa is issued an identity document, which is a passport sized 8 page booklet. Inside this passport is the individual's national identification number, and this page discusses how it's format can be validated using regular expressions.

First lets have a look at the format of this ID. It consists of 13 individual numbers of which the first 6 are the individuals date of birth (YYMMDD), followed by the gender (0-4 for male, 5-9 for female), a three digit number code combining the two, another individual number to indicate whether or not the individual is a South African citizen (0 for yes, 1 for no), and then another digit (which is usually either 8 or 9), and to finish a control digit. In regular expression terms this all takes on the following format:


As you can see the second to last digit can be any number, not just 8 or 9, leaving this option open to the existence of a more extended number range. Here is a JavaScript example of the above code in action:

<title>Republic of South Africa Identity Document Validation with JavaScript</title>

<script language="JavaScript">

function said_validate(said)

var regsaid = /^([0-9]){2}([0-1][0-9])([0-3][0-9])([0-9]){4}([0-1])([0-9]){2}?$/;

if(regsaid.test(said) == false)

document.getElementById("status").innerHTML = "ID number is not yet valid.";


document.getElementById("status").innerHTML = "You have entered a valid ID number!";



<style type="text/css">
body {

div {
width: 100%;
text-align: center;

span {
color: #000099;
font: 8pt verdana;

input {
color: #000000;
background: #F8F8F8;
border: 1px solid #353535;
font: 8pt verdana;

<span id="status">Please enter a valid Identity Document ID number.</span><br>
<input type="text" name="said" onkeyup="said_validate(this.value);">


Want to leave a comment?

No problem. Just enter your email and password below.

register | home | reminder

myDesignTool Networking •