How to use the google-libphonenumber.PhoneNumberFormat.NATIONAL function in google-libphonenumber

To help you get started, we’ve selected a few google-libphonenumber examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github celo-org / celo-monorepo / packages / utils / src / phoneNumbers.ts View on Github external
function prependToFormMobilePhoneNumber(
  parsedNumber: PhoneNumber,
  regionCode: string,
  prefix: string
) {
  if (phoneUtil.getNumberType(parsedNumber) === PhoneNumberType.MOBILE) {
    return parsedNumber
  }

  let nationalNumber = phoneUtil.format(parsedNumber, PhoneNumberFormat.NATIONAL)
  // Nationally formatted numbers sometimes contain leading 0
  if (nationalNumber.charAt(0) === '0') {
    nationalNumber = nationalNumber.slice(1)
  }
  // If the number already starts with prefix, don't prepend it again
  if (nationalNumber.startsWith(prefix)) {
    return null
  }

  const adjustedNumber = phoneUtil.parse(prefix + nationalNumber, regionCode)
  return phoneUtil.getNumberType(adjustedNumber) === PhoneNumberType.MOBILE ? adjustedNumber : null
}
github MoveOnOrg / Spoke / src / lib / phone-format.js View on Github external
export const getDisplayPhoneNumber = (e164Number, country = "US") => {
  const phoneUtil = PhoneNumberUtil.getInstance();
  const parsed = phoneUtil.parse(e164Number, country);
  return phoneUtil.format(parsed, PhoneNumberFormat.NATIONAL);
};
github ChristianRich / phone-number-extractor / lib / extractor.js View on Github external
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;