This is just a wrapper class of libphonenumber by Davide Mendolia's extension libphonenumber-for-PHP
Requirements ¶
...requirements of using this extension (e.g. Yii 1.1 or above)...
Installation ¶
- Download and extract extension files to the directory protected/vendors
Usage ¶
Wherever you want to validate the phone number,use the following codes
Yii::setPathOfAlias('libphonenumber',Yii::getPathOfAlias('application.vendors.libphonenumber'));
$phonenumber=new libphonenumber\LibPhone($your_phone_number);
/**
* Checking the number is valid or not
*
* @return boolean
*/
$phonenumber->validate(); //return true if valid
//to convert to international format
$phonenumber->toInternational();
//to get national format
$phonenumber->toNational();
//to get E164 format
$phonenumber->toE164();
/*to get out of country calling number format
*need to pass the region value
*/
$phonenumber->toOutOfCountryCallingNumber($region);
Nice
Nice one.
Quick Correction
If you are running into the error that the file does not exist think about changing
Yii::setPathOfAlias('libphonenumber',Yii::getPathOfAlias('application.vendors.libphonenumber'));
to 'applications.vendor.libphonenumber' - my file name was vendor and not vendors
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.