PHP Classes

NumVerify PHP Phone Number Validation: Verify phone numbers using NumVerify API

Recommend this page to a friend!
  Info   View files Documentation   View files View files (28)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2023-10-21 (19 hours ago) RSS 2.0 feedNot yet rated by the usersTotal: 1 This week: 1All time: 11,157 This week: 119Up
Version License PHP version Categories
numverify-api-client 1.0MIT/X Consortium ...7Wireless and Mobile, Web services, PHP 7
Description 

Author

This package can verify phone numbers using NumVerify API.

It implements a client for the APILayer NumVerify API to perform several types of operations with phone numbers.

Currently it can:

- Validate a given phone number with country code

- Get the list of countries and country code dialing prefixes

Picture of Smoren  Freelight
  Performance   Level  
Innovation award
Innovation award
Nominee: 14x

 

Documentation

Numverify API Client Library for PHP

Numverify phone number validation and country API client library for PHP.

Coverage Status License

Features

* Phone number validation API * Validate phone numbers * Carrier information * Line type * Location info: country, local information * Phone number formats * Countries API * List of countries * Country names, country codes, dialing codes

Numverify API documentation: https://numverify.com/documentation

Setup

Add the library to your composer.json file in your project:

{
  "require": {
      "markrogoyski/numverify-api-client-php": "2.*"
  }
}

Use composer to install the library:

$ php composer.phar install

Composer will install Numverify API Client Library for PHP inside your vendor folder. Then you can add the following to your .php files to the use library with Autoloading.

require_once(__DIR__ . '/vendor/autoload.php');

Alternatively, use composer on the command line to require and install Numverify API Client Library:

$ php composer.phar require markrogoyski/numverify-api-client-php:2.*

Minimum Requirements

* PHP 7.2

Note: For PHP 7.0 and 7.1, use v1.0 (require markrogoyski/numverify-api-client-php:1.*)

Usage

Create New API

$accessKey = 'AccountAccessKeyGoesHere';
$api       = new \Numverify\Api($accessKey);

Phone Number Validation API

$phoneNumber          = '14158586273';
$validatedPhoneNumber = $api->validatePhoneNumber($phoneNumber);
 
// Phone number information
if ($validatedPhoneNumber->isValid()) {
    $number              = $validatedPhoneNumber->getNumber();               // 14158586273
    $localFormat         = $validatedPhoneNumber->getLocalFormat();          // 4158586273
    $internationalPrefix = $validatedPhoneNumber->getInternationalFormat();  // +14158586273
    $countryPrefix       = $validatedPhoneNumber->getCountryPrefix();        // +1
    $countryCode         = $validatedPhoneNumber->getCountryCode();          // US
    $countryName         = $validatedPhoneNumber->getCountryName();          // United States of America
    $location            = $validatedPhoneNumber->getLocation();             // Novato
    $carrier             = $validatedPhoneNumber->getCarrier();              // AT&T Mobility LLC
    $lineType            = $validatedPhoneNumber->getLineType();             // mobile
}

// Use optional country code parameter for local (non-E.164) phone numbers
$phoneNumber = '4158586273';
$countryCode = 'US';
$validatedPhoneNumber = $api->validatePhoneNumber($phoneNumber, $countryCode);
 
// PHP Interfaces
$stringRepresentation = (string) $validatedPhoneNumber;
$jsonRepresentation   = json_encode($validatedPhoneNumber);

Countries API

$countries = $api->getCountries();
 
// Find countries (by country code or by name)
$unitedStates = $countries->findByCountryCode('US');
$japan        = $countries->findByCountryName('Japan');
 
// Country information
$usCountryCode = $unitedStates->getCountryCode();  // US
$usCountryName = $unitedStates->getCountryName();  // United States
$usDialingCode = $unitedStates->getDialingCode();  // +1
 
$japanCountryCode = $japan->getCountryCode();       // JP
$japanCountryName = $japan->getCountryName();       // Japan
$japanDialingCode = $japan->getDialingCode();       // +81
 
// Country collection is iterable
foreach ($countries as $country) {
    $countryCode = $country->getCountryCode();
    $countryName = $country->getCountryName();
    $dialingCode = $country->getDialingCode();
}
 
// Country collection PHP interfaces
$numberOfCountries  = count($countries);
$jsonRepresentation = json_encode($numberOfCountries);
 
// Country PHP interfaces
$stringRepresentation = (string) $unitedStates;      // US: United States (+1)
$jsonRepresentation   = json_encode($unitedStates);

Options

// Construct API to use HTTPS for API calls
$useHttps = true;
$api      = new \Numverify\Api($accessKey, $useHttps);  // Optional second parameter

Exceptions

API failures throw a `NumverifyApiFailureException`

// Numverify API server error
try {
    $validatedPhoneNumber = $api->validatePhoneNumber($phoneNumber);
} catch (\Numverify\Exception\NumverifyApiFailureException $e) {
    $statusCode = $e->getStatusCode();  // 500
    $message    = $e->getMessage();     // Unknown error - 500 Internal Server Error
}

// Numverify API failure response
try {
    $validatedPhoneNumber = $api->validatePhoneNumber($phoneNumber);
} catch (\Numverify\Exception\NumverifyApiFailureException $e) {
    $statusCode = $e->getStatusCode();  // 200
    $message    = $e->getMessage();     // Type:invalid_access_key Code:101 Info:You have not supplied a valid API Access Key.
}

Unit Tests

$ cd tests
$ phpunit

Coverage Status

Standards

Numverify API Client Library for PHP conforms to the following standards:

* PSR-1 - Basic coding standard (http://www.php-fig.org/psr/psr-1/) * PSR-4 - Autoloader (http://www.php-fig.org/psr/psr-4/) * PSR-12 - Extended coding style guide (http://www.php-fig.org/psr/psr-12/)

License

Numverify API Client Library for PHP is licensed under the MIT License.


  Files folder image Files  
File Role Description
Files folder image.github (1 directory)
Files folder imagesrc (1 file, 3 directories)
Files folder imagetests (6 files, 3 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE.txt Doc. Documentation
Accessible without login Plain text file Makefile Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:1
This week:1
All time:11,157
This week:119Up