Вход на сайт

Просмотр новости

Найдите то, что Вас интересует

How to check if a phone number is real, not just correctly formatted? (Python)

Дата публикации: 30-09-2026 10:52:13


I’m validating user phone numbers in a Python backend and I’ve hit the limits of what regex can do.
Users submit the same number in every format imaginable:
+44 7700 900123
07700 900123
07700900123
(0) 7700-900123
Step 1 was normalizing everything to E.164 (strip non-digits, prepend country code when the user selects one):
def clean_number(raw: str) -> str:
return "".join(ch for ch in raw if ch.isdigit() or ch == "+")
Step 2 was a format check:
pattern = r"^\+?\d{7,15}$"
The problem: this regex happily accepts numbers that are format-valid but fake — +123456789012345 passes, 00000000000 passes. It also can’t tell me:
Whether the number is actually allocated/in service — format-correct is not the same as real
Whether it’s mobile or landline — I’m sending SMS OTP codes, and sending to a landline fails silently in some gateways
Whether the leading zero should be dropped — UK 07700… becomes +447700…, but naively prepending 44 breaks numbers that keep their trunk prefix
I looked at libphonenumber. It handles parsing and formatting well, but its validation is still numbering-plan based (a number can be “possible” without being in service), and its carrier metadata is static prefix data that can lag behind real allocations.
How do services that offer a phone number lookup API validate against actual allocations and return line type and carrier? Is there an open numbering-plan dataset I can build this on myself, or is querying a lookup service the standard production approach?
Context: signup flow, a few hundred validations/day, SMS OTP delivery, Python.
6 posts - 4 participants
Read full topic

Схожие новости

#Наименование новостиТональностьИнформативностьДата публикации
1How do you stop the same person from signing up again and again on a free plan?07.3716-09-2026
2How should a small service business design a simple booking flow without hurting conversions?08.0621-09-2026
3Best way to build a responsive multi-field booking form?06.3801-10-2026
4Как городской телефон определяет номер? Запускаем Caller ID в домашних условиях07.8125-09-2026
5What’s a sensible way to handle a daily word puzzle backend in PHP?06.6218-09-2026
6Mobile Menu Help08.9802-10-2026
7What makes a small web utility useful and trustworthy?05.3305-10-2026
8Availability of their API hostname OpenCart04.7609-09-2026
9flight registrations020.2328-09-2026
10Эксперт Бедеров: мошенники изолируют жертву от близких для создания вакуума лжи011.5302-10-2026

Классификация: . Схожих патентов: 0. Схожих новостей: 10. Тональность: 0. Информативность: 15.58. Источник: www.sitepoint.com.