Yii 1.1: libphonenumber

One simple libphonenumber php class for Yii framework
9 followers

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);

Resources

Total 2 comments

#17821 report it
stephent at 2014/07/25 04:47am
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

#12827 report it
sirin k at 2013/04/14 11:49am
Nice

Nice one.

Leave a comment

Please to leave your comment.

Create extension