If your app sends SMS or places calls in France, every phone number has to reach your telephony layer in E.164: +33 followed by exactly nine digits. Users and CSV files rarely hand you that. Here is the small normalizer we ended up with, plus the edge cases it covers.
What French numbers look like in the wild
A French number has ten digits in its national form: a leading 0, then nine digits (06 12 34 56 78). In E.164 you drop the 0 and add the country code: +33612345678.
Real inputs we see in imports and forms:
| Input | Where it comes from |
|---|---|
06 12 34 56 78 | Typed by a human, spaces every two digits |
06.12.34.56.78 | Same, with dots (very common in France) |
0612345678 | Spreadsheet cell |
+33 6 12 34 56 78 | Already international |
0033 6 12 34 56 78 | International prefix written with 00 |
+33 (0)6 12 34 56 78 | The "optional zero" notation |
33612345678 | Country code without the + |
612345678 | Spreadsheet ate the leading zero (number column) |
Every one of these should become +33612345678.
The normalizer
import re FR_E164 = re.compile(r"^\+33[1-9]\d{8}$") def to_e164_fr(raw: str) -> str | None: """Return the French number in E.164 (+33XXXXXXXXX), or None if it is not one.""" if not raw: return None s = re.sub(r"[^\d+]", "", raw) # keep digits and '+' if s.startswith("00"): # 0033... -> +33... s = "+" + s[2:] if s.startswith("+330") and len(s) == 13: # +33 (0)6... -> +336... s = "+33" + s[4:] if s.startswith("+"): candidate = s elif s.startswith("33") and len(s) == 11: # 33612345678 candidate = "+" + s elif s.startswith("0") and len(s) == 10: # 0612345678 candidate = "+33" + s[1:] elif len(s) == 9 and s[0] != "0": # 612345678 (lost leading zero) candidate = "+33" + s else: return None return candidate if FR_E164.match(candidate) else None A few tests that document the behaviour:
import pytest @pytest.mark.parametrize("raw", [ "06 12 34 56 78", "06.12.34.56.78", "0612345678", "+33 6 12 34 56 78", "0033 6 12 34 56 78", "+33 (0)6 12 34 56 78", "33612345678", "612345678", ]) def test_valid_inputs(raw): assert to_e164_fr(raw) == "+33612345678" @pytest.mark.parametrize("raw", [ "+33435638300060", # too long: two numbers glued together "+3306123456", # too short "0012", # junk "2026-11-29", # a date that landed in the phone column "", ]) def test_rejected_inputs(raw): assert to_e164_fr(raw) is None Why the strict final check matters
A generic E.164 regex (^\+[1-9]\d{6,14}$) accepts +33435638300060: it is a plausible length for some country. For France it is garbage, usually two numbers concatenated in one cell. Telephony APIs reject it, and if you send a batch of those, you get a burst of 4xx errors that can trip whatever rate limiting or circuit breaker sits in front of your provider. Validate the country-specific shape (+33 plus exactly nine digits, first one not zero) before anything leaves your app.
Searching a contact by phone
The other half of the problem is lookup: your database may contain numbers stored in different formats (older rows, imports, manual edits). When someone searches 06 12 34 56 78, we generate the likely stored variants and match any of them:
def phone_search_variants(query: str) -> list[str]: digits = re.sub(r"\D", "", query) if len(digits) < 6: return [] variants = {query, digits} if digits.startswith("0") and len(digits) == 10: variants |= {"+33" + digits[1:], "33" + digits[1:]} if digits.startswith("33") and len(digits) >= 11: variants |= {"+" + digits, "0" + digits[2:]} if len(digits) >= 9: variants.add(digits[-9:]) # last nine digits match every format return list(variants) The last-nine-digits variant is the workhorse: +33612345678, 0612345678 and 33612345678 all end with 612345678.
Displaying numbers back to French users
Store E.164, display the national format. French users expect pairs of digits:
def display_fr(e164: str) -> str: national = "0" + e164[3:] # +33612345678 -> 0612345678 return " ".join(national[i:i + 2] for i in range(0, 10, 2)) # 06 12 34 56 78 Wrap-up
- Strip everything but digits and
+, then handle00,(0), a missing+and a missing leading zero. - Validate the French shape strictly, not just "looks like E.164".
- Store E.164, search with variants (last nine digits), display in pairs.
We use this in Voice Pilot, an AI phone receptionist for French tradespeople and small businesses, where caller numbers, callback numbers and imported contacts all go through the same normalizer before any call or SMS. If you handle other countries, the same pattern works: one strict regex per country, and a library like phonenumbers when you need the full international picture.

