Regular Expressions 101

Community Patterns

South African ID Numbers

0

Regular Expression
PCRE2 (PHP >=7.3)

/
(([0-9]{2})(0|1)([0-9])([0-3])([0-9]))([ ]?)(([0-9]{4})([ ]?)([0-1][8]([ ]?)[0-9]))
/
gm

Description

This is a Regex for South African ID numbers.

SA ID numbers' format is the following:

YYMMDD GGGG CAZ

YYMMDD is for the year, month and day. GGGG is for Gender: 0000-4999 is female; 5000-9999 is male. C is for Citizenship: 0 is born in SA and 1 is permanent residency. A is always 8, was used until the late 1980's to indicate race. Z is a strategically calculated number making the ID number valid or invalid using Luhn's algorithm.

This Regex also makes provision for spaces (people write ID numbers differently):

  • 1234567890123
  • 123456 7890 123
  • 123456 7890 12 3

This Regex is also elsaticsearch compatible, I have test it in a lot of search engines, and it works every time.

Feel free to use this Regex.

Submitted by Riaan van den Berg - a year ago (Last modified 8 months ago)