Javascript Validate South African Identity Number

function validateSAID(elementID)
{
var SAIDRegEx = /^(((\d{2}((0[13578]|1[02])(0[1-9]|[12]\d|3[01])|(0[13456789]|1[012])(0[1-9]|[12]\d|30)|02(0[1-9]|1\d|2[0-8])))|([02468][048]|[13579][26])0229))(( |-)(\d{4})( |-)(\d{3})|(\d{7}))/;
if (SAIDRegEx.test(document.getElementById(elementID).value)) return true; return false;
}

Take a look at this blog post for more information about SA ID number structure and validation.

One Response to Javascript Validate South African Identity Number

  1. Ryan Michael James says:

    Thanks! This is AWESOME! You saved me a few hours work!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: