Contact
Australian Mobile Number Regex
Australian mobile numbers start with 04 domestically, or +61 4 internationally, followed by eight more digits. They are usually written in a 4-3-3 grouping such as 0412 345 678. This pattern accepts both prefixes and optional single spaces in the usual positions, which suits sign-up, booking and delivery forms for Australian users. The Australian Communications and Media Authority reserves ranges such as 0491 570 156 to 0491 570 159 for fictional use, which makes them good test values. The honest limit is that it does not know which ranges are allocated.
Pattern (JavaScript)
/^(?:\+61 ?|0)4[0-9]{2} ?[0-9]{3} ?[0-9]{3}$/Starts at the start of the line/string, then (the text "+61", then a space, optionally (zero or one time) OR the character "0"), then the character "4", then a digit, exactly 2 times, then a space, optionally (zero or one time), then a digit, exactly 3 times, then a space, optionally (zero or one time), then a digit, exactly 3 times, then the end of the line/string.
Limit: Checks the format only; it cannot tell whether the number is active.
Examples
Matches
- ✓ 0412 345 678
- ✓ +61 412 345 678
- ✓ 0491570156
Does not match
- ✗ 0312 345 678
- ✗ 0412 345 67
- ✗ +64 412 345 678
Try it
0 matches (JavaScript engine)
0412 345 678
+61 412 345 678
0491570156
0312 345 678
0412 345 67
+64 412 345 678Code in 8 languages
Converted automatically from the JavaScript pattern; language-specific notes are shown where the syntax or support differs.
JavaScript
const re = /^(?:\+61 ?|0)4[0-9]{2} ?[0-9]{3} ?[0-9]{3}$/g;
const text = "0412 345 678";
const matches = [...text.matchAll(re)].map((m) => m[0]);
console.log(matches);Python
import re
pattern = re.compile(r'^(?:\+61 ?|0)4[0-9]{2} ?[0-9]{3} ?[0-9]{3}$')
text = '0412 345 678'
matches = [m.group(0) for m in pattern.finditer(text)]
print(matches)PHP
<?php
$pattern = '/^(?:\+61 ?|0)4[0-9]{2} ?[0-9]{3} ?[0-9]{3}$/';
$text = '0412 345 678';
preg_match_all($pattern, $text, $matches);
print_r($matches[0]);Java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("^(?:\\+61 ?|0)4[0-9]{2} ?[0-9]{3} ?[0-9]{3}$");
String text = "0412 345 678";
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^(?:\+61 ?|0)4[0-9]{2} ?[0-9]{3} ?[0-9]{3}$`)
text := "0412 345 678"
fmt.Println(re.FindAllString(text, -1))
}C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"^(?:\+61 ?|0)4[0-9]{2} ?[0-9]{3} ?[0-9]{3}$");
var text = "0412 345 678";
foreach (Match m in pattern.Matches(text))
{
Console.WriteLine(m.Value);
}Rust
// Cargo.toml: regex = "1"
use regex::Regex;
fn main() {
let re = Regex::new(r"^(?:\+61 ?|0)4[0-9]{2} ?[0-9]{3} ?[0-9]{3}$").unwrap();
let text = "0412 345 678";
for m in re.find_iter(text) {
println!("{}", m.as_str());
}
}- Add regex = "1" under [dependencies] in Cargo.toml.
Ruby
pattern = /^(?:\+61 ?|0)4[0-9]{2} ?[0-9]{3} ?[0-9]{3}$/
text = '0412 345 678'
matches = text.to_enum(:scan, pattern).map { Regexp.last_match[0] }
p matchesFrequently asked questions
- Why does the pattern require 4 after the prefix?
- All Australian mobile numbers belong to the 04 range, while landlines use area codes such as 02, 03, 07 and 08. Requiring 4 separates mobiles from landlines.
- How do I accept +61 0412 345 678?
- That form is incorrect because the 0 should be dropped after +61, but users still type it. Remove a 0 that appears right after +61 before testing.
- Which numbers are safe to use as examples?
- ACMA reserves a small block of numbers, including 0491 570 156 to 0491 570 159, for use in fiction and examples. Using them avoids accidentally publishing a real customer's number.