Contact
North American Toll-Free Number Regex
Toll-free numbers in the United States and Canada use a small set of special area codes: 800, 833, 844, 855, 866, 877 and 888. This pattern accepts those prefixes with an optional leading 1 or +1, optional parentheses and space, dot or dash separators. It is handy for directory listings, call tracking tools and support pages where you want to highlight or validate free-to-call numbers. The honest limit is that new toll-free prefixes such as 822 may be introduced over time, so the list of codes needs occasional updates.
Pattern (JavaScript)
/^(?:\+?1[ .-]?)?\(?8(?:00|33|44|55|66|77|88)\)?[ .-]?[0-9]{3}[ .-]?[0-9]{4}$/Starts at the start of the line/string, then (a literal "+", optionally (zero or one time), then the character "1", then one of the characters .-, optionally (zero or one time)), optionally (zero or one time), then a literal "(", optionally (zero or one time), then the character "8", then (the text "00" OR the text "33" OR the text "44" OR the text "55" OR the text "66" OR the text "77" OR the text "88"), then a literal ")", optionally (zero or one time), then one of the characters .-, optionally (zero or one time), then a digit, exactly 3 times, then one of the characters .-, optionally (zero or one time), then a digit, exactly 4 times, then the end of the line/string.
Limit: Checks the format only; it cannot tell whether the number is in service.
Examples
Matches
- ✓ 1-800-555-0199
- ✓ (888) 555-0100
- ✓ 877.555.0123
Does not match
- ✗ 1-801-555-0199
- ✗ 800-555-019
- ✗ 899-555-0100
Try it
0 matches (JavaScript engine)
1-800-555-0199
(888) 555-0100
877.555.0123
1-801-555-0199
800-555-019
899-555-0100Code in 8 languages
Converted automatically from the JavaScript pattern; language-specific notes are shown where the syntax or support differs.
JavaScript
const re = /^(?:\+?1[ .-]?)?\(?8(?:00|33|44|55|66|77|88)\)?[ .-]?[0-9]{3}[ .-]?[0-9]{4}$/g;
const text = "1-800-555-0199";
const matches = [...text.matchAll(re)].map((m) => m[0]);
console.log(matches);Python
import re
pattern = re.compile(r'^(?:\+?1[ .-]?)?\(?8(?:00|33|44|55|66|77|88)\)?[ .-]?[0-9]{3}[ .-]?[0-9]{4}$')
text = '1-800-555-0199'
matches = [m.group(0) for m in pattern.finditer(text)]
print(matches)PHP
<?php
$pattern = '/^(?:\+?1[ .-]?)?\(?8(?:00|33|44|55|66|77|88)\)?[ .-]?[0-9]{3}[ .-]?[0-9]{4}$/';
$text = '1-800-555-0199';
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("^(?:\\+?1[ .-]?)?\\(?8(?:00|33|44|55|66|77|88)\\)?[ .-]?[0-9]{3}[ .-]?[0-9]{4}$");
String text = "1-800-555-0199";
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^(?:\+?1[ .-]?)?\(?8(?:00|33|44|55|66|77|88)\)?[ .-]?[0-9]{3}[ .-]?[0-9]{4}$`)
text := "1-800-555-0199"
fmt.Println(re.FindAllString(text, -1))
}C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"^(?:\+?1[ .-]?)?\(?8(?:00|33|44|55|66|77|88)\)?[ .-]?[0-9]{3}[ .-]?[0-9]{4}$");
var text = "1-800-555-0199";
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"^(?:\+?1[ .-]?)?\(?8(?:00|33|44|55|66|77|88)\)?[ .-]?[0-9]{3}[ .-]?[0-9]{4}$").unwrap();
let text = "1-800-555-0199";
for m in re.find_iter(text) {
println!("{}", m.as_str());
}
}- Add regex = "1" under [dependencies] in Cargo.toml.
Ruby
pattern = /^(?:\+?1[ .-]?)?\(?8(?:00|33|44|55|66|77|88)\)?[ .-]?[0-9]{3}[ .-]?[0-9]{4}$/
text = '1-800-555-0199'
matches = text.to_enum(:scan, pattern).map { Regexp.last_match[0] }
p matchesFrequently asked questions
- Why are only certain 8xx codes accepted?
- Only specific 8xx codes are designated as toll-free in North America. Other codes beginning with 8, such as 801, are ordinary geographic area codes.
- Are toll-free numbers free from mobile phones?
- Usually yes in North America, though calls from abroad may be charged or blocked. That is a billing question; the regex only identifies the number format.
- How do I add a new toll-free prefix?
- Add the last two digits to the alternation inside 8(?:...), for example 22 for 822. Keeping the list explicit makes the change easy to review.
Related patterns
- US Phone Number^(?:\+1[ .-]?)?\(?[2-9][0-9]{2}\)?[ .-]?[2-9][0-9]{2}[ .-]?[0-9]{4}$
- Australian Mobile Number^(?:\+61 ?|0)4[0-9]{2} ?[0-9]{3} ?[0-9]{3}$
- Canada Postal Code^[ABCEGHJ-NPRSTVXY][0-9][ABCEGHJ-NPRSTV-Z] ?[0-9][ABCEGHJ-NPRSTV-Z][0-9]$
- Fax Line with Label^(?:fax|f)\s*[:.]?\s*\+?[0-9(][0-9 ().-]{6,}[0-9]$