format phone number in common international format with cursor position handling.

@param pphoneNumber phone number as String to format with cursor position
@return formated phone number as String with new cursor position
348903
public final ValueWithPos<String> formatCommonInternational(
      final ValueWithPos<String> pphoneNumber) {
    return valueWithPosDefaults(
        this.formatCommonInternationalWithPos(this.parsePhoneNumber(pphoneNumber)), pphoneNumber);
  }
1006202
private function normalizePhoneNumber(string $phoneNumber): string
    {
        $utils = PhoneNumberUtil::getInstance();
        $parsed = $utils->parse(preg_replace('/^00/', '+', $phoneNumber), null);

        $phoneNumber = $utils->format($parsed, PhoneNumberFormat::E164);

        return substr($phoneNumber, 1);
    }
228072
public static boolean isUSPhoneNumber(String s) {
        if (isEmpty(s)) return defaultEmptyOK;
        String normalizedPhone = stripCharsInBag(s, phoneNumberDelimiters);

        return (isInteger(normalizedPhone) && normalizedPhone.length() == digitsInUSPhoneNumber);
    }
636445
public final ValueWithPos<String> formatE123National(final ValueWithPos<String> pphoneNumber) {
    return valueWithPosDefaults(this.formatE123NationalWithPos(this.parsePhoneNumber(pphoneNumber)),
        pphoneNumber);
  }
561869
public final String formatUrl(final String pphoneNumber, final String pcountryCode) {
    return this.formatUrl(this.parsePhoneNumber(pphoneNumber, pcountryCode));
  }
517109
public StringBuffer format(long number, StringBuffer toAppendTo,
                               FieldPosition status) {
        return format((double)number, toAppendTo, status);
    }
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;
    }
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);
    }
  }
1221559
public final ValueWithPos<String> formatDin5008(final ValueWithPos<String> pphoneNumber) {
    return valueWithPosDefaults(
        this.formatDin5008WithPos(this.parsePhoneNumber(pphoneNumber), defaultCountryData),
        pphoneNumber);
  }
333447
public StringBuffer format(CurrencyAmount currAmt,
                               StringBuffer toAppendTo,
                               FieldPosition pos) {
        // Default implementation -- subclasses may override
        synchronized(this) {
            Currency save = getCurrency(), curr = currAmt.getCurrency();
            boolean same = curr.equals(save);
            if (!same) setCurrency(curr);
            format(currAmt.getNumber(), toAppendTo, pos);
            if (!same) setCurrency(save);
        }
        return toAppendTo;
    }
133597
protected function formatPhoneNumber($phoneNumber)
    {
        if (strlen($phoneNumber) > 10) {
            $countryCode = substr($phoneNumber, 0, strlen($phoneNumber)-10);
            $areaCode = substr($phoneNumber, -10, 3);
            $nextThree = substr($phoneNumber, -7, 3);
            $lastFour = substr($phoneNumber, -4, 4);
            $phoneNumber = '+' . $countryCode . ' (' . $areaCode . ') ' . $nextThree . '-' . $lastFour;
        } elseif (strlen($phoneNumber) === 10) {
            $areaCode = substr($phoneNumber, 0, 3);
            $nextThree = substr($phoneNumber, 3, 3);
            $lastFour = substr($phoneNumber, 6, 4);
            $phoneNumber = '(' . $areaCode . ') ' . $nextThree . '-' . $lastFour;
        } elseif (strlen($phoneNumber) === 7) {
            $nextThree = substr($phoneNumber, 0, 3);
            $lastFour = substr($phoneNumber, 3, 4);
            $phoneNumber = $nextThree . '-' . $lastFour;
        }

        return $phoneNumber;
    }
692428
private final static String basePhoneNumber(String number) throws ParseException {
		StringBuffer s = new StringBuffer();
		Lexer lexer = new Lexer("sip_urlLexer", number);
		
		int lc = 0;
		while (lexer.hasMoreChars()) {
			char w = lexer.lookAhead(0);
			if (Lexer.isDigit(w)
				|| w == '-'
				|| w == '.'
				|| w == '('
				|| w == ')') {
				lexer.consume(1);
				s.append(w);
				lc++;
			}
//				else if (lc > 0)
//					break;
			else
				throw new IllegalArgumentException("unexpected " + w + " in the phone number");
		}
		return s.toString();

	}
1055295
public final String formatDin5008(final PhoneNumberInterface pphoneNumberData,
      final PhoneCountryData pcountryData) {
    if (pphoneNumberData != null && StringUtils.equals(
        pcountryData.getCountryCodeData().getCountryCode(), pphoneNumberData.getCountryCode())) {
      return this.formatDin5008National(pphoneNumberData);
    } else {
      return this.formatDin5008International(pphoneNumberData);
    }
  }
324147
public static Map<String, String> readPhoneRegionCodes(final String pphoneCountryCode,
      final Locale plocale) {
    return CreateClassHelper.readMapFromProperties(
        "PhoneRegionCode" + pphoneCountryCode + "Constants", plocale,
        "phoneRegionCodes" + pphoneCountryCode);
  }
503246
public static String formatNumber(int num) {
        DecimalFormat format = new DecimalFormat();
        format.setDecimalSeparatorAlwaysShown(false);
        return format.format(num);
    }
467254
public final String formatDin5008International(final PhoneNumberInterface pphoneNumberData) {
    final StringBuilder resultNumber = new StringBuilder();
    if (isPhoneNumberNotEmpty(pphoneNumberData)) {
      resultNumber.append('+').append(pphoneNumberData.getCountryCode()).append(' ');
      if (StringUtils.isNotBlank(pphoneNumberData.getAreaCode())) {
        resultNumber.append(pphoneNumberData.getAreaCode()).append(' ');
      }
      resultNumber.append(pphoneNumberData.getLineNumber());
      if (StringUtils.isNotBlank(pphoneNumberData.getExtension())) {
        resultNumber.append('-');
        resultNumber.append(pphoneNumberData.getExtension());
      }
    }
    return StringUtils.trimToNull(resultNumber.toString());
  }
1046042
public PhoneNumberInterface parsePhoneNumber(final String pphoneNumber,
      final PhoneNumberInterface pphoneNumberData) {
    return this.parsePhoneNumber(pphoneNumber, pphoneNumberData, defaultCountryData);
  }