Malaysian IC Number (MyKad / NRIC) Regex for Go
/^(\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 Go. 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 Go project — whether you're validating in a Gin handler, a gRPC service, or a command-line tool.
Go Implementation
// Malaysian IC Number (MyKad / NRIC)
// ReDoS-safe | RegexVault — Identity & PII > National Identity Numbers
package validation
import "regexp"
var malaysianIcNumberMykadNricRe = regexp.MustCompile(`^(\d{2})(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])-(0[0-9]|1[0-6])-(\d{4})$`)
func ValidateMalaysianIcNumberMykadNric(s string) bool {
return malaysianIcNumberMykadNricRe.MatchString(s)
}
// Example
// fmt.Println(ValidateMalaysianIcNumberMykadNric("880101-14-5555")) // trueTest 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 Go developers because Go's RE2 engine is inherently safe from catastrophic backtracking, but this pattern has been additionally verified for correctness. 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