Australian Phone Number Regex for Java
/^(?:\+61|0)(?:\s|-)?(?:[2-578])(?:[\s.-]?[0-9]{4}){2}$|^(?:\+61|0)4[0-9]{2}(?:[\s.-]?[0-9]{3}){2}$/What this pattern does
This page provides a comprehensive, battle-tested regular expression for matching australian phone number, ported and verified for Java. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. 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 Phone Number
// ReDoS-safe | RegexVault — Localization > Phone Numbers
import java.util.regex.Pattern;
public class AustralianPhoneNumberValidator {
private static final Pattern PATTERN =
Pattern.compile("^(?:\\+61|0)(?:\\s|-)?(?:[2-578])(?:[\\s.-]?[0-9]{4}){2}$|^(?:\\+61|0)4[0-9]{2}(?:[\\s.-]?[0-9]{3}){2}$");
public static boolean validate(String input) {
return PATTERN.matcher(input).matches();
}
// Example
public static void main(String[] args) {
System.out.println(validate("+61 2 9374 4000")); // true
}
}Test Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
+61 2 9374 4000 | +61 0 1234 5678 |
02 9374 4000 | 0192 345 678 |
+61412345678 | +61 2 1234 567 |
0412 345 678 | 02 9374 40000 |
+61 8 9321 0000 | — |
When to use this pattern
This pattern is drawn from the Localization > Phone Numbers 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
Australia's 10-digit numbers (2 area code + 8 local) replaced the older variable-length system in the late 1990s. Historical data may have shorter numbers.
Technical Notes
Australian area codes: 02 (NSW/ACT), 03 (VIC/TAS), 07 (QLD), 08 (SA/WA/NT). Mobile numbers start with 04 (04xx = 10-digit mobile). 05 is reserved. +61 replaces the leading 0.
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