Giter VIP home page Giter VIP logo

phone-number-validation-using-api-layer's Introduction

Phone Number Validation using API Layer

This Jupyter Notebook demonstrates how to use the API Layer to validate phone numbers.

Requirements

To run this code, you will need:

  • Python 3.6 or higher
  • Jupyter Notebook
  • The requests and json Python packages

Installation

You can install the required packages using pip:

pip install requests
pip install json

Usage

  1. Open the Jupyter Notebook file in Jupyter Notebook.
  2. Replace the API key in the headers variable with your own API key. You can get a free API key by signing up at api-layer.com.
  3. Modify the phone number in the params variable to the phone number you want to validate.
  4. Run the notebook cells in order. The output will indicate whether the phone number is valid or not, and if available, the carrier information.

Note that the code includes error handling and response parsing logic, so you should see helpful error messages if something goes wrong with the API request.

License

This code is licensed under the MIT License.

phone-number-validation-using-api-layer's People

Contributors

antonygn avatar

Watchers

 avatar

phone-number-validation-using-api-layer's Issues

The phone number is first validated using the apilayer API. If the phone number is valid, we use the phonenumbers library to parse the phone number and retrieve carrier information.

import requests
import json
import phonenumbers
from phonenumbers import carrier

number = "+254790295419"

Validate phone number using API

url = "https://api.apilayer.com/number_verification/validate"
params = {"number": number}
headers = {"apikey": "hwKpz11LVNRgK97gaRYS2Puz4uNITDhg"}

response = requests.get(url, params=params, headers=headers)

if response.status_code == 200:
result = json.loads(response.text)
if result["valid"]:
# If phone number is valid, parse it using phonenumbers library and retrieve carrier information
try:
parsed_number = phonenumbers.parse(number)
carrier_name = carrier.name_for_number(parsed_number, 'en')
if carrier_name:
print(f"The phone number {number} is valid and belongs to {carrier_name}.")
else:
print(f"The phone number {number} is valid but the carrier information is not available.")
except phonenumbers.NumberParseException as e:
print(f"The phone number {number} could not be parsed: {e}")
else:
print(f"The phone number {number} is not valid.")
else:
print(f"An error occurred: {response.status_code}")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.