giddyeffects/yii2-numverify

A Yii2 extension to use the NumVerify API, which offers a full-featured yet simple RESTful JSON API for national and international phone number validation and information lookup for a total of 232 countries around the world

dev-master 2017-04-05 10:38 UTC

This package is not auto-updated.

Last update: 2024-06-09 01:13:09 UTC


README

A Yii2 extension to use the NumVerify API, which offers a full-featured yet simple RESTful JSON API for national and international phone number validation and information lookup for a total of 232 countries around the world

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist "giddyeffects/yii2-numverify":"@dev"

or add

"giddyeffects/yii2-numverify": "@dev"

to the require section of your composer.json file.

Usage

First get an Numverify API key here.

Once the extension is installed, simply add the following code in your application configuration:

return [
    //....
    'components' => [
        //...
        'numverify' => [
            'class' => 'giddyeffects\numverify\Numverify',
            'access_key' => 'YOUR_NUMVERIFY_API_KEY',
        ],
    ],
];

You can now access the extension via \Yii::$app->numverify;

For more details refer to the Numverify Documentation.

Example

$response = \Yii::$app->numverify->verify(4158586273, ['country_code'=>'us']);
//check if there's an error
if ($response->error){
    echo $response->error->info;
}
else{
    if($response->valid=='1'){
        echo "Number '$response->number' is valid.";
        echo "<br>";
        echo "local_format: $response->local_format";
        echo "<br>";
        echo "international_format: $response->international_format";
        echo "<br>";
        echo "country_prefix: $response->country_prefix";
        echo "<br>";
        echo "country_code: $response->country_code";
        echo "<br>";
        echo "country_name: $response->country_name";
        echo "<br>";
        echo "location: $response->location";
        echo "<br>";
        echo "carrier: $response->carrier";
        echo "<br>";
        echo "line_type: $response->line_type";
        echo "<br>";
    }
    else{
        echo "Number given is not valid.";
    }
}