Get Phone Number Information using Python

Today we code how to get phone number information using python. Let’s do it.

Installation

To do so we are using phonenumbers module. phonenumbers is one of the modules that provide various features like providing basic information about the mobile number, validation of a phone number, etc.

Just open terminal and type this command and hit enter.

pip3 install phonenumbers

This is a Python port of Google’s libphonenumber library It supports Python 2.5-2.7 and Python 3.x (in the same codebase, with no 2to3 conversion needed).

Code

import phonenumbers
from phonenumbers import carrier, geocoder, timezone

mobileNo = input("Enter Mobile Number with Country code: ")
mobileNo = phonenumbers.parse(mobileNo)

# get timezone a phone number
print(timezone.time_zones_for_number(mobileNo))

# Getting carrier of a phone number
print(carrier.name_for_number(mobileNo, "en"))

# Getting region information
print(geocoder.description_for_number(mobileNo, "en"))

# Validating a phone number
print(phonenumbers.is_valid_number(mobileNo))

# Checking possibility of a number
print(phonenumbers.is_possible_number(mobileNo))

# follow @code_snail in insta

It’s very simple right. Now try this code by yourself and share it with your friends.

explore phonenumbers: https://pypi.org/project/phonenumbers/

More python mini projects:

Support CodeSnail

If you appreciate my work, or if it has helped you along your journey. It would mean a lot to me if you could write a message on my wall and share a cup of coffee (or tea) with me.

Buy Me A Coffee

Related Articles

Leave a Comment

Copy link
Powered by Social Snap