Download Cheat sheet PDF 12 pages · syntax, editors, patterns, Unicode, performance, debugging
Blog

Extract international phone numbers from text

Phone numbers vary so wildly across countries that no single regex catches them all. Here's a reasonable starting point.

The general pattern

const PHONE_RE = /\+?\d[\d\s()-]{6,18}\d/g;

const text = `
Contact us at +1 (555) 123-4567 (US),
+44 20 7946 0958 (UK),
+91 98765 43210 (India),
or 555.1234 (local).
`;
const phones = text.match(PHONE_RE);
// matches the international + local numbers

This is loose by design. It catches almost any digit sequence with phone-like punctuation, but it'll have false positives (date ranges, ID numbers).

Stricter per-country patterns

For specific countries, use the patterns from our library:

For real production use, use libphonenumber

Google's libphonenumber handles every country's rules, validates numbers, formats them in international/national/E.164 forms, and detects the country from the number alone.

// JavaScript with libphonenumber-js
import { parsePhoneNumber } from "libphonenumber-js";

const phone = parsePhoneNumber("+919876543210");
console.log(phone.country);          // "IN"
console.log(phone.formatInternational()); // "+91 98765 43210"
console.log(phone.isValid());        // true

For Python: phonenumbers. For Go: github.com/nyaruka/phonenumbers. For Java: libphonenumber directly from Google.

Use regex to find candidates in unstructured text, then validate each with libphonenumber.


← Back to blog