Australian Medicare Number Regex for Java
/^([2-6][0-9]{9})(?:\s*([1-9]))?$/What this pattern does
This page provides a well-structured, multi-part regular expression for matching australian medicare number, ported and verified for Java. 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 Java project — whether you're validating in a Spring Boot controller, a Jakarta EE service, or a standalone utility class.
Java Implementation
// Australian Medicare Number
// ReDoS-safe | RegexVault — Identity & PII > Health Identifiers
import java.util.regex.Pattern;
public class AustralianMedicareNumberValidator {
private static final Pattern PATTERN =
Pattern.compile("^([2-6][0-9]{9})(?:\\s*([1-9]))?$");
public static boolean validate(String input) {
return PATTERN.matcher(input).matches();
}
// Example
public static void main(String[] args) {
System.out.println(validate("2123456701")); // true
}
}Test Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
2123456701 | 1123456701 |
2123456701 1 | 7123456701 |
6999999991 | 212345670 |
21234567011 | 21234567010 |
| — | 2123456701A |
When to use this pattern
This pattern is drawn from the Identity & PII > Health Identifiers category and carries a ReDoS-safe certification. That matters for Java developers because critical in Java applications since the JVM regex engine uses backtracking and is susceptible to ReDoS without careful pattern design. 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 IRN distinguishes family members sharing a Medicare card. When storing, preserve both the 10-digit number and the IRN — the full reference is: XXXXXXXXXX/1 (where 1 is the cardholder, 2-9 are dependants).
Technical Notes
Australian Medicare numbers start with 2-6 (4=concessional). 10-digit number + 1-digit IRN (Individual Reference Number, 1-6, identifies individuals on a family card). Checksum: weighted sum of first 9 digits, compare to 10th. Services Australia assigns and validates.
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