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, (*1)
Installation
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
php composer.phar require --prefer-dist "giddyeffects/yii2-numverify":"@dev"
or add, (*4)
"giddyeffects/yii2-numverify": "@dev"
to the require section of your composer.json
file., (*5)
Usage
First get an Numverify API key here., (*6)
Once the extension is installed, simply add the following code in your application configuration:, (*7)
return [
//....
'components' => [
//...
'numverify' => [
'class' => 'giddyeffects\numverify\Numverify',
'access_key' => 'YOUR_NUMVERIFY_API_KEY',
],
],
];
You can now access the extension via \Yii::$app->numverify;
, (*8)
For more details refer to the Numverify Documentation., (*9)
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.";
}
}