How can we use the python-phonenumbers library to determine whether a particular phone number is a mobile number or landline number?
How can we use the python-phonenumbers library to determine whether a particular phone number is a mobile number or landline number?
Use phonenumbers.phonenumberutil.number_type to get the number type (after you have parsed the number). e.g.
x = phonenumbers.parse("0282784492", "AU")
phonenumbers.phonenumberutil.number_type(x)
So if you wanted to use x if it was not a fixed line number you could do:
if phonenumbers.phonenumberutil.number_type(x) is not phonenumbers.PhoneNumberType.FIXED_LINE:
# Do something...
The possible phone number types are:
FIXED_LINE = 0MOBILE = 1FIXED_LINE_OR_MOBILE = 2TOLL_FREE = 3PREMIUM_RATE = 4SHARED_COST = 5VOIP = 6PERSONAL_NUMBER = 7PAGER = 8UAN = 9VOICEMAIL = 10UNKNOWN = 99See the full descriptions here.