Skip to content

Remedial Activity: Malaysia's myKad Number

To the outsider who did not research this beforehand, the Malaysia's myKad number (Malaysia's NRIC number) may seem like an intelligible string of 12 random numbers. However, not everything about them is truly random! With it, one can definitely obtain some useful information.

Disclaimer

To the best of my ability, I will use either examples with censored digits or numbers I know that are purposefully invalid. Any usage of real myKad numbers is clearly incidental; should you be amongst the few that are affected, please revert to me as quickly as possible and I will remove it in favor of hopefully another invalid myKad number. Apologies in advance!!

There are some pieces of information that can be derived from a Malaysian's myKad number:

Check for Valid myKad Number Format

Before we start our information elicitation process, we have to consider how we want our inputs to be. Feel free to choose one you are comfortable with, but for the rest of this activity, we will regard a proper representation as just a string of 12 numbers with hyphens (-). For example, 960101-10-xxxx.

Task: Write a function is_valid(mykad) that takes in a string value in mykad and returns True if it is a valid myKad number, and False otherwise.

Template
mykad.py
def is_valid(mykad):
    return True     # edit code from here

Birth Date

The first 6 digits in a myKad number constitutes one's birth date (i.e., yymmdd). Some examples are listed in the table below.

myKad No. Birth Date
951001-01-6xxx 1 October 1995
020304-13-2xxx 4 March 2002
301108-43-6xxx 8 November 1930
301108-43-0xxx 8 November 2030

Take note of the last two examples in this table - comparing and contrasting the two myKad numbers, there is a difference in the 4th last number (i.e., 6 vs. 0). This digit is a random number, as is with the remaining 3 digits in the myKad number. However, we can clarify which century this person was born in.

  • those born before 2000 tend to have one of digits 5, 6 or 7, whereas
  • those born on 2000 onwards tend to have one of digits 0, 1, 2 or 3

Task: Write a function get_birth_date(mykad) that takes in a string value in mykad and returns the determined birth date. Return False if no valid birth date can be derived.

Sample output
>>> mykad_num = '301108-00-6000'
>>> get_birth_date(mykad_num)
8 Nov 1930

Location of Birth Registration

The middle two digits in between the hyphens (i.e., 7th and 8th digits) can determine where the birth registration of a person has been conducted. In the usual case, it is one of Malaysia's states:

State PB
Johor 01, 21-24
Kedah 02, 25-27
Kelantan 03, 28, 29
Malacca 04, 30
Negeri Sembilan 05, 31, 59
Pahang 06, 32, 33
Penang 07, 34-35
Perak 08, 36-38
Perlis 09, 40
Selangor 10, 41-44
Terengganu 11, 45, 46
Sabah 12, 47-49
Sarawak 13, 50-53
Federal Territory of Kuala Lumpur 14, 54-57
Federal Territory of Labuan 15, 58
Federal Territory of Putrajaya 16

Gender

Using negative indexes

Using negative indexes here to check for the last digit (i.e., [-1]) can be a valid approach. However, you may want to ensure that the length of that last portion in the mykad value passed in is correct.

References