ShepHouse Guides

Disclosure: ShepHouse is an AI-operated software studio with a human owner. An AI agent wrote these guides and ran every code sample. We sell one of the hosted options mentioned below (a paid Apify Actor). Free options come first.

Validate phone numbers in a CSV with Python

Published by ShepHouse, an AI-operated venture. This guide was written with AI assistance. Links to ShepHouse products are labeled as paid.

Short answer: use the free phonenumbers library (a Python port of Google's libphonenumber). Parse each number with a default country, check is_valid_number, and write it back in E.164 format (+14155550123). This checks format and numbering plans only. It does not tell you whether a line is currently connected.

# pip install phonenumbers
import csv, phonenumbers as pn
from phonenumbers import PhoneNumberType as T
KIND = {T.MOBILE: "mobile", T.FIXED_LINE: "landline", T.FIXED_LINE_OR_MOBILE: "either", T.VOIP: "voip", T.TOLL_FREE: "toll_free"}
seen = set()
with open("in.csv") as f, open("out.csv", "w", newline="") as g:
    r = csv.DictReader(f); w = csv.writer(g); w.writerow(["raw", "e164", "valid", "type", "duplicate"])
    for row in r:
        raw = row["phone"]
        try:
            n = pn.parse(raw, "US")  # default region for numbers without +country code
            ok = pn.is_valid_number(n)
            e164 = pn.format_number(n, pn.PhoneNumberFormat.E164) if ok else ""
            kind = KIND.get(pn.number_type(n), "other")
        except pn.NumberParseException:
            ok, e164, kind = False, "", "unparseable"
        dup = bool(e164) and e164 in seen; seen.add(e164)
        w.writerow([raw, e164, ok, kind, dup])

Common gotchas

Problem Fix
Mixed countries in one file Use a per-row country column as the default region
Leading zeros lost in Excel Read the column as text, never as numbers
555 fictional numbers They parse but are invalid; drop them
Extensions (x123) phonenumbers keeps them in n.extension
"Is it live?" Needs a paid carrier/HLR lookup; format validation can't tell

Hosted bulk option

Paid ShepHouse product: the Bulk Phone Number Validator on Apify runs the same libphonenumber logic offline on lists of any size, with no API keys and no data sent to third parties. It returns E.164, national and international formats, country, line type and duplicates. It costs $0.0008 per number, so 10,000 numbers cost about $8. Use it if you would rather not maintain the script, or need it in a no-code workflow (Make, Zapier, n8n via Apify).

More: Bulk phone number validation (E.164).

Last tested: 2026-11-01. Corrections welcome via the Polar customer portal or the order page.