Unparalleled suite of productivity-boosting Web APIs & cloud-based micro-service applications for developers and companies of any size.

APILocation

Build a PHP Phone Number Validator Using Numverify

Validate A Phone Number In Your PHP Web App Using NumVerify API

One of the most important ways for companies serving in the international arena to get ahead of their competitors is user satisfaction. If the applications or websites owned by the businesses are used by people in many parts of the world, the verification of user information is the first step of user satisfaction.

The process of verifying the numbers registered by people in different parts of the world while entering your applications seems to be a troublesome process at first. How does the process of verifying the numbers of hundreds of country codes in the world from one place sound? With the API service provided by Numverify, it supports more than 200 world codes and offers real time number verification through a phone validator API.

In this article, we will integrate Numverify’s API into the PHP programming language. So let’s start.

Integration to PHP Programming Language

An API key is needed to integrate and use the real-time number verification service provided by Numverify. You can choose one of the affordable and flexible packages from Numverify’s official website, sign up, and then get an API key.

After obtaining the API key, we create a PHP project and paste the following codes.

<?php
$client = new http\Client;
$request = new http\Client\Request;
$request->setRequestUrl(‘https://apilayer.net/api/validate?access_key=77*****d&number=4158586273&country_code=US&format=1’);
$request->setRequestMethod(‘GET’);
$request->setOptions(array());
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();

The API key we get as a parameter to the API provided by Numverify is ‘access_key’, the number we want to validate is ‘number’, the country code of the number we want to validate is ‘country_code’ and the ‘format’ field is 1 for the return type of this service to be JSON. We set it to and run our code.

After running this code we get the following response.

{
“valid”: true,
“number”: “14158586273”,
“local_format”: “4158586273”,
“international_format”: “+14158586273”,
“country_prefix”: “+1”,
“country_code”: “US”,
“country_name”: “United States of America”,
“location”: “Novato”,
“carrier”: “AT&T Mobility LLC”,
“line_type”: “mobile”
}

Numverify returns a very detailed response as a service response. If the number you want to validate is valid, it contains much more information such as country prefix, line type, carrier, etc. of this number.

For a different example, we paste the code below into the PHP project and run it again.

<?php
$client = new http\Client;
$request = new http\Client\Request;
$request->setRequestUrl(‘https://apilayer.net/api/validate?access_key=77*****d&number=2087599036&country_code=GB&format=1’);
$request->setRequestMethod(‘GET’);
$request->setOptions(array());
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();

After running this code we get the following response.

{
“valid”: true,
“number”: “442087599036”,
“local_format”: “02087599036”,
“international_format”: “+442087599036”,
“country_prefix”: “+44”,
“country_code”: “GB”,
“country_name”: “United Kingdom of Great Britain and Northern Ireland”,
“location”: “London”,
“carrier”: “”,
“line_type”: “landline”
}

Now let’s test a number that is not valid.

<?php
$client = new http\Client;
$request = new http\Client\Request;
$request->setRequestUrl(‘https://apilayer.net/api/validate?access_key=77*****d&number=99999&country_code=TR&format=1’);
$request->setRequestMethod(‘GET’);
$request->setOptions(array());
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();

After running this code we get the following response.

{
“valid”: false,
“number”: “9099999”,
“local_format”: “”,
“international_format”: “”,
“country_prefix”: “”,
“country_code”: “”,
“country_name”: “”,
“location”: “”,
“carrier”: “”,
“line_type”: null
}

As you can see, Numverify detected a non-valid number very quickly and returned it.

Ready to get started verifying numbers easily?

The number verification service provided by Numverify helps businesses by supporting more than 200 country codes. In particular, businesses aiming at customer satisfaction can directly increase customer satisfaction by using Numverify services in real time.

Sign up for Numverify today!

Related posts
API

The 5 Types of API Marketplaces

API

Building Your Own Geolocation App with IP Geolocation API

APIIPLocation

What Is Geoblocking And How Does It Work?

API

Microservices Design: API Gateway Pattern

Leave a Reply

Your email address will not be published. Required fields are marked *