Malaysian IC Number (MyKad / NRIC) Regex for PHP
/^(\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 PHP. 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 PHP project — whether you're validating in a Laravel validator, a WordPress plugin, or a standalone PHP script.
Php Implementation
<?php
// Malaysian IC Number (MyKad / NRIC)
// ReDoS-safe | RegexVault — Identity & PII > National Identity Numbers
define('MALAYSIAN_IC_NUMBER_MYKAD_NRIC_PATTERN', '/^(\d{2})(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])-(0[0-9]|1[0-6])-(\d{4})$/');
function validate_malaysian_ic_number_mykad_nric(string $input): bool {
return (bool) preg_match(MALAYSIAN_IC_NUMBER_MYKAD_NRIC_PATTERN, $input);
}
// Example
var_dump(validate_malaysian_ic_number_mykad_nric("880101-14-5555")); // bool(true)Test Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
880101-14-5555 | 880101145555 |
990231-10-1234 | 880101-17-5555 |
010115-01-0001 | 880001-14-5555 |
001231-12-9999 | 880132-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 PHP developers because especially relevant in PHP where PCRE backtracking limits can trigger silent failures on malicious input. 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