numverify – A Phone Number Validation API

Recently in one of the client’s projects, we integrated a numverify API for phone number validation. The numverify service checks if the phone number is in a valid format and if it really exists. We normally apply only format validation for phone numbers no matter if the phone number really exists or not. But if someone is looking for real phone number validation then you are at the right place.

A valid phone number is important for a number of websites. For example, if a website sends a verification code or OTP on mobile then it is crucial to check if a given phone number really exists.

Another example is you might want to send voice or text communications on the mobile number ensuring Telephone Consumer Protection Act.

In all these scenarios, you must want to validate the phone number’s existence.

In this article, I show you how to do phone number validation using numverify. Using numverify, apart from phone number validation you also get some extra information like location, country, carrier, line type(mobile or landline), etc.

Get numverify API Key

The numverify provides different kinds of plans from free to enterprise-level. Depending on requirements, the user can pick any suitable plan. You can check out their subscription plans.

I recommend starting with their free plans. See how it performs and then go for paid plans.

That being said, sign up on numverify. Once you logged in you will get access to the dashboard where you can find your API key. Copy the API key which we will need in a moment.

API Key

Phone Number Validation Using numverify and PHP

Once we get the API key we are ready to send an API call to numverify. We use the PHP cURL to send a request to the API and receive a response. Let’s say we need to verify the number ‘14158586273’ so we will write a code as follows.

<?php
// set API Access Key
$access_key = 'YOUR_API_KEY';

// set phone number
$phone_number = '14158586273';

// Initialize CURL:
$ch = curl_init('http://apilayer.net/api/validate?access_key='. $access_key .'&number='. $phone_number);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Store the data:
$json = curl_exec($ch);
curl_close($ch);

// Decode JSON response:
$validationResult = json_decode($json, true);

if ($validationResult['valid']) {
    echo "Phone number is valid";
} else {
    echo "Phone number is not valid";
}

In response, numverify set verify=>true if the number is valid. If you print the output it will look like the below format.

{
   "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"
 }

Notice the line_type in response. Here the value for line_type is ‘mobile’. It means you can send text communication to this number. This value can be a landline, special_services, etc.

I hope you understand phone number validation with numverify and PHP. Please share your thoughts and suggestions in the comment section below.

Related Articles

If you liked this article, then please subscribe to our YouTube Channel for video tutorials.

Leave a Reply

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