Coverage for src/couchers/phone/check.py: 88%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import phonenumbers
4def is_e164_format(phone):
5 """Return true if string is in E.164 format with leading +, for example "+46701740605" """
6 return len(phone) > 2 and phone[0] == "+" and phone[1:].isdigit() and len(phone) <= 16
9def is_known_operator(phone):
10 """Return true if phone is in E.164 format with leading +, and has the
11 correct amount of digits considering the country and operator.
12 """
14 if not is_e164_format(phone):
15 return False
17 z = phonenumbers.parse(phone)
18 return phonenumbers.is_valid_number(z)