format phone number in Common national format.

@param pphoneNumberData phone number to format
@return formated phone number as String
196230
public final String formatCommonNational(final PhoneNumberInterface pphoneNumberData) {
    final StringBuilder resultNumber = new StringBuilder();
    if (isPhoneNumberNotEmpty(pphoneNumberData)) {
      PhoneCountryData phoneCountryData = null;
      for (final PhoneCountryCodeData country : CreatePhoneCountryConstantsClass.create()
          .countryCodeData()) {
        if (StringUtils.equals(country.getCountryCode(), pphoneNumberData.getCountryCode())) {
          phoneCountryData = country.getPhoneCountryData();
          break;
        }
      }
      if (phoneCountryData == null) {
        return null;
      }
      resultNumber.append(phoneCountryData.getTrunkCode()).append(' ');
      resultNumber.append(this.groupIntoParts(pphoneNumberData.getAreaCode(), 2));
      resultNumber.append(" / ");
      resultNumber.append(this.groupIntoParts(pphoneNumberData.getLineNumber(), 2));
      if (StringUtils.isNotBlank(pphoneNumberData.getExtension())) {
        resultNumber.append(" - ");
        resultNumber.append(this.groupIntoParts(pphoneNumberData.getExtension(), 2));
      }
    }
    return StringUtils.trimToNull(resultNumber.toString());
  }
727497
function(n, countryCode){

        const number = phoneUtil.parse(n, countryCode),
            isPossibleNumber = phoneUtil.isPossibleNumber(number),
	        res = {
                input: n,
                countryCode: countryCode,
                isPossibleNumber: isPossibleNumber,
                isPossibleNumberWithReason: phoneUtil.isPossibleNumberWithReason(number)
	        };

        if(isPossibleNumber){
            res.isPossibleNumber = true;
            res.isNumberValid = phoneUtil.isValidNumber(number);
            res.countryCode = countryCode;
            res.formatted = phoneUtil.formatInOriginalFormat(number, countryCode);
            res.national = phoneUtil.format(number, PNF.NATIONAL);
            res.international = phoneUtil.format(number, PNF.INTERNATIONAL)
        }

        switch (phoneUtil.isPossibleNumberWithReason(number)){

            case PNV.IS_POSSIBLE:
                res.isPossibleNumberWithReason = 'IS_POSSIBLE';
            break;

            case PNV.INVALID_COUNTRY_CODE:
                res.isPossibleNumberWithReason = 'INVALID_COUNTRY_CODE';
            break;

            case PNV.TOO_SHORT:
                res.isPossibleNumberWithReason = 'TOO_SHORT';
            break;

            case PNV.TOO_LONG:
                res.isPossibleNumberWithReason = 'TOO_LONG';
            break;
        }

        return res;
    }
1360824
@Override
    public StringBuffer format(Object number,
                               StringBuffer toAppendTo,
                               FieldPosition pos) {
        if (number instanceof Long) {
            return format(((Long)number).longValue(), toAppendTo, pos);
        } else if (number instanceof BigInteger) {
            return format((BigInteger) number, toAppendTo, pos);
        } else if (number instanceof java.math.BigDecimal) {
            return format((java.math.BigDecimal) number, toAppendTo, pos);
        } else if (number instanceof android.icu.math.BigDecimal) {
            return format((android.icu.math.BigDecimal) number, toAppendTo, pos);
        } else if (number instanceof CurrencyAmount) {
            return format((CurrencyAmount)number, toAppendTo, pos);
        } else if (number instanceof Number) {
            return format(((Number)number).doubleValue(), toAppendTo, pos);
        } else {
            throw new IllegalArgumentException("Cannot format given Object as a Number");
        }
    }
1271269
public final String formatCommonInternational(final String pphoneNumber,
      final String pcountryCode) {
    return this.formatCommonInternational(this.parsePhoneNumber(pphoneNumber, pcountryCode));
  }
1200950
public final ValueWithPos<String> formatDin5008International(
      final ValueWithPos<String> pphoneNumber) {
    return valueWithPosDefaults(
        this.formatDin5008InternationalWithPos(this.parsePhoneNumber(pphoneNumber)), pphoneNumber);
  }
345905
public static NumberFormat makeNumberFormat(int digits) {
    // Prefer predefined number formats where applicable.
    // TODO: cache others, too?
    switch(digits){
    case 0:
      return NF0;
    case 2:
      return NF2;
    case 3:
      return NF3;
    case 4:
      return NF4;
    case 6:
      return NF6;
    case 8:
      return NF8;
    }
    final NumberFormat nf = NumberFormat.getInstance(Locale.US);
    nf.setMaximumFractionDigits(digits);
    nf.setMinimumFractionDigits(digits);
    nf.setGroupingUsed(false);
    return nf;
  }
560855
private function getFormattingTemplate($numberPattern, $numberFormat)
    {
        // Creates a phone number consisting only of the digit 9 that matches the
        // numberPattern by applying the pattern to the longestPhoneNumber string.
        $longestPhoneNumber = '999999999999999';
        $m = new Matcher($numberPattern, $longestPhoneNumber);
        $m->find();
        $aPhoneNumber = $m->group();
        // No formatting template can be created if the number of digits entered entered so far
        // is longer than the maximum the current formatting rule can accommodate.
        if (mb_strlen($aPhoneNumber) < mb_strlen($this->nationalNumber)) {
            return '';
        }
        // Formats the number according to $numberFormat
        $template = preg_replace('/' . $numberPattern . '/' . PhoneNumberUtil::REGEX_FLAGS, $numberFormat, $aPhoneNumber);
        // Replaces each digit with character self::$digitPlattern
        $template = preg_replace('/9/', self::$digitPattern, $template);
        return $template;
    }
69825
public final ValueWithPos<String> formatCommonWithPos(
      final ValueWithPos<PhoneNumberData> pphoneNumberData, final PhoneCountryData pcountryData) {
    if (pphoneNumberData != null && pcountryData != null
        && StringUtils.equals(pcountryData.getCountryCodeData().getCountryCode(),
            pphoneNumberData.getValue().getCountryCode())) {
      return this.formatCommonNationalWithPos(pphoneNumberData);
    } else {
      return this.formatCommonInternationalWithPos(pphoneNumberData);
    }
  }
811633
public final ValueWithPos<String> formatE123(final ValueWithPos<String> pphoneNumber) {
    return this.formatE123WithPos(this.parsePhoneNumber(pphoneNumber), defaultCountryData);
  }
805021
public PhoneNumberInterface parsePhoneNumber(final String pphoneNumber,
      final PhoneNumberInterface pphoneNumberData, final PhoneCountryData pcountryData) {
    if (pphoneNumber == null) {
      return null;
    }
    final ValueWithPos<PhoneNumberData> formatedValue =
        this.parsePhoneNumber(new ValueWithPos<>(pphoneNumber, -1), pphoneNumberData, pcountryData);
    return formatedValue.getValue();
  }
1043984
public function phoneFormatByCountry($phone, $country = 'BR', $format = 'n')
    {
        $phoneUtil = PhoneNumberUtil::getInstance();
        try {
            $phoneParse = $phoneUtil->parse($phone, $country);
        } catch (\libphonenumber\NumberParseException $e) {
            return null;
        }

        if ($format == 'n') {
            $method = PhoneNumberFormat::NATIONAL;
        } elseif ($format == 'i') {
            $method = PhoneNumberFormat::INTERNATIONAL;
        } else {
            $method = PhoneNumberFormat::E164;
        }

        return $phoneUtil->format($phoneParse, $method);
    }
1068842
public ValueWithPos<PhoneNumberData> parsePhoneNumber(final ValueWithPos<String> pphoneNumber,
      final String pcountryCode) {
    return this.parsePhoneNumber(pphoneNumber, pcountryCode, Locale.ROOT);
  }
367568
public final boolean isPhoneNumberEmpty(final PhoneNumberInterface pphoneNumberData) {
    return pphoneNumberData == null || StringUtils.isBlank(pphoneNumberData.getCountryCode())
        || StringUtils.isBlank(pphoneNumberData.getLineNumber());
  }
691723
public PhoneNumberData parsePhoneNumber(final String pphoneNumber, final String pcountryCode,
      final Locale plocale) {
    return (PhoneNumberData) this.parsePhoneNumber(pphoneNumber, new PhoneNumberData(),
        CreatePhoneCountryConstantsClass.create(plocale).countryMap()
            .get(StringUtils.defaultString(pcountryCode)));
  }
231475
function format(number, countryCode, type) {
    try {
        var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance();
        var numberObj = phoneUtil.parseAndKeepRawInput(number, countryCode || '');
        type = (typeof type == "undefined") ? i18n.phonenumbers.PhoneNumberFormat.INTERNATIONAL : type;
        if (type == 0) {
            return phoneUtil.format(numberObj, i18n.phonenumbers.PhoneNumberFormat.INTERNATIONAL).replace(/[\-\(\)\s\.]/g, '').replace('ext', ',');
        }
        return phoneUtil.format(numberObj, type);
    } catch (e) {
        return "";
    }
}
475053
public String formatted()
    {
        String callerID = ""; //$NON-NLS-1$
        if (this.name != null)
        {
            callerID += this.name;
        }
        if (this.number != null)
        {
            if (callerID.length() > 1)
            {
                callerID += " "; //$NON-NLS-1$
            }
            callerID += "<" + this.number + ">"; //$NON-NLS-1$ //$NON-NLS-2$
        }
        return callerID;
    }
783902
public StringBuffer format(double number, StringBuffer toAppendTo,
                               FieldPosition status) {
        // find the number
        int i;
        for (i = 0; i < choiceLimits.length; ++i) {
            if (!(number >= choiceLimits[i])) {
                // same as number < choiceLimits, except catchs NaN
                break;
            }
        }
        --i;
        if (i < 0) i = 0;
        // return either a formatted number, or a string
        return toAppendTo.append(choiceFormats[i]);
    }