REGEXVAULTv2.0
Identity & PII/National Identity Numbers
Verified Safe

Malaysian IC Number (MyKad / NRIC) Regex for Python

/^(\d{2})(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])-(0[0-9]|1[0-6])-(\d{4})$/

What this pattern does

This page provides a well-structured, multi-part regular expression for matching malaysian ic number (mykad / nric), ported and verified for Python. Identity and credential patterns need both correctness and safety, since they're frequent targets for adversarial input. The snippet below is ready to drop into your Python project — whether you're validating in a Django view, a FastAPI endpoint, or a standalone data processing script.

Python Implementation

Python
# Malaysian IC Number (MyKad / NRIC)
# ReDoS-safe | RegexVault — Identity & PII > National Identity Numbers

import re

malaysian_ic_number_mykad_nric_pattern = re.compile(r'^(\d{2})(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])-(0[0-9]|1[0-6])-(\d{4})$')

def validate_malaysian_ic_number_mykad_nric(value: str) -> bool:
    return bool(malaysian_ic_number_mykad_nric_pattern.fullmatch(value))

# Example
print(validate_malaysian_ic_number_mykad_nric("880101-14-5555"))  # True

Test Cases

Matches (Valid)
Rejects (Invalid)
880101-14-5555880101145555
990231-10-1234880101-17-5555
010115-01-0001880001-14-5555
001231-12-9999880132-14-5555
8801014-14-555

When to use this pattern

This pattern is drawn from the Identity & PII > National Identity Numbers category and carries a ReDoS-safe certification. That matters for Python developers because particularly important in Python web servers where CPU-bound regex operations can stall concurrent request handling. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

The MyKad encodes date of birth and gender directly in the number — exposure of the IC number reveals both. Foreigners use a different format with different state codes (60-93 for foreign workers).

Technical Notes

Structure: YYMMDD (date of birth) + state code (01-16) + sequential number. Last digit odd=male, even=female. State codes: 01=Johor, 02=Kedah, ..., 14=Federal Territory, 15=Sabah, 16=Sarawak. YYMMDD does not validate day-of-month correctness (e.g., 990231 is Feb 31).

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern