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
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.
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.
$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.";
}
}