/**
  * This should be called when the bean is saved. The bean itself will be passed by reference
  * 
  * @param SugarBean bean - the bean performing the save
  * @param array params - an array of paramester relevant to the save, most likely will be $_REQUEST
  */
 public function save($bean, $params, $field, $properties, $prefix = '')
 {
     parent::save($bean, $params, $field, $properties, $prefix);
     if (isset($params[$prefix . $field])) {
         $bean->{$field} = $params[$prefix . $field];
     }
     /*
      * Additional code for phone number format to E.164
      * add by xye@sugarcrm.com begin
      */
     $phoneNumberStr = $bean->{$field};
     /*
      * ISO 3166-1 two-letter country code
      * http://www.iso.org/iso/country_names_and_code_elements
      */
     global $sugar_config;
     $default_region = "US";
     if (isset($sugar_config['phonenumber_default_region']) && !empty($sugar_config['phonenumber_default_region'])) {
         $default_region = $sugar_config['phonenumber_default_region'];
     }
     $phoneUtil = PhoneNumberUtil::getInstance();
     //_ppl('phone number--->'.$phoneNumberStr);
     try {
         $phoneNumberProto = $phoneUtil->parseAndKeepRawInput($phoneNumberStr, $default_region);
         $isValid = $phoneUtil->isValidNumber($phoneNumberProto);
         //_ppl(array($phoneNumberStr, $isValid, $phoneNumberProto, $phoneUtil->format($phoneNumberProto, PhoneNumberFormat::E164)));
         if ($isValid) {
             if ($phoneNumberProto->hasExtension()) {
                 $bean->{$field} = $phoneUtil->format($phoneNumberProto, PhoneNumberFormat::E164) . ' ext. ' . $phoneNumberProto->getExtension();
             } else {
                 $bean->{$field} = $phoneUtil->format($phoneNumberProto, PhoneNumberFormat::E164);
             }
         }
     } catch (NumberParseException $e) {
         _ppl($e->__toString());
         //                         echo $e;
     }
     /*
      * Additional code for phone number format to E.164
      * add by xye@sugarcrm.com end
      */
 }
<?php

use com\google\i18n\phonenumbers\PhoneNumberUtil;
use com\google\i18n\phonenumbers\PhoneNumberFormat;
use com\google\i18n\phonenumbers\NumberParseException;
require_once 'PhoneNumberUtil.php';
$swissNumberStr = "044 668 18 00";
$phoneUtil = PhoneNumberUtil::getInstance();
try {
    $swissNumberProto = $phoneUtil->parseAndKeepRawInput($swissNumberStr, "CH");
    var_dump($swissNumberProto);
} catch (NumberParseException $e) {
    echo $e;
}
$isValid = $phoneUtil->isValidNumber($swissNumberProto);
//return true
var_dump($isValid);
// Produces "+41446681800"
echo $phoneUtil->format($swissNumberProto, PhoneNumberFormat::INTERNATIONAL) . PHP_EOL;
echo $phoneUtil->format($swissNumberProto, PhoneNumberFormat::NATIONAL) . PHP_EOL;
echo $phoneUtil->format($swissNumberProto, PhoneNumberFormat::E164) . PHP_EOL;
echo $phoneUtil->formatOutOfCountryCallingNumber($swissNumberProto, "US") . PHP_EOL;
function getCountryCodeForValidRegion($regionCode)
{
    require_once 'custom/include/lib/phonenumbers/PhoneNumberUtil.php';
    $phoneUtil = PhoneNumberUtil::getInstance();
    $metadata = $phoneUtil->getMetadataForRegion($regionCode);
    return $metadata->getCountryCode();
}