1. Parse and Format a Phone Number
This program parses a phone number and formats it in the international format.
import phonenumbers
from phonenumbers import PhoneNumberFormat, format_number
phone_number = phonenumbers.parse("+14155552671", "US")
formatted_number = format_number(phone_number, PhoneNumberFormat.INTERNATIONAL)
print(f"Formatted Number: {formatted_number}")
Formatted Number: +1 415-555-2671
2. Validate a Phone Number
This program checks whether a phone number is valid or not.
import phonenumbers
phone_number = phonenumbers.parse("+14155552671", "US")
is_valid = phonenumbers.is_valid_number(phone_number)
print(f"Is the phone number valid? {'Yes' if is_valid else 'No'}")
Is the phone number valid? Yes
3. Get the Location of a Phone Number
This program retrieves the location associated with a phone number.
import phonenumbers
from phonenumbers import geocoder
phone_number = phonenumbers.parse("+14155552671", "US")
location = geocoder.description_for_number(phone_number, "en")
print(f"Location: {location}")
#source Code --> clcoding.com
Location: San Francisco, CA
4. Carrier Detection
This program detects the carrier of a given phone number.
import phonenumbers
from phonenumbers import carrier
phone_number = phonenumbers.parse("+14155552671", "US")
phone_carrier = carrier.name_for_number(phone_number, "en")
print(f"Carrier: {phone_carrier}")
#source Code --> clcoding.com
Carrier:
5. Time Zone Detection
This program retrieves the time zones associated with a phone number.
import phonenumbers
from phonenumbers import timezone
phone_number = phonenumbers.parse("+14155552671", "US")
time_zones = timezone.time_zones_for_number(phone_number)
print(f"Time Zones: {', '.join(time_zones)}")
#source Code --> clcoding.com
Time Zones: America/Los_Angeles
0 Comments:
Post a Comment