How to use the google-libphonenumber.PhoneNumberFormat.E164 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 MoveOnOrg / Spoke / src / lib / phone-format.js View on Github external
export const getFormattedPhoneNumber = (cell, country = "US") => {
  const phoneUtil = PhoneNumberUtil.getInstance();
  // we return an empty string vs null when the phone number is inValid
  // because when the cell is null, batch inserts into campaign contacts fail
  // then when contacts have cell.length < 12 (+1), it's deleted before assignments are created
  try {
    const inputNumber = phoneUtil.parse(cell, country);
    const isValid = phoneUtil.isValidNumber(inputNumber);
    if (isValid) {
      return phoneUtil.format(inputNumber, PhoneNumberFormat.E164);
    }
    return "";
  } catch (e) {
    log.error(e);
    return "";
  }
};
github mikesparr / typescript-postgres-auth-example / src / utils / formatter.ts View on Github external
return formattedDate ? formattedDate : null;
      case DataType.EMAIL:
        if (this.isValidEmail(value)) {
          return `${value}`.trim().toLowerCase();
        } else {
          return null;
        }
      case DataType.PHONE:
        let phone: string = `${value}`.trim(); // trim
        const phoneNumber: PhoneNumber = this.phoneUtil.parseAndKeepRawInput(phone, "US");
        // check if valid, otherwise return null
        if (!this.phoneUtil.isValidNumberForRegion(phoneNumber, "US")) {
          logger.debug(`Phone ${phone} was invalid`);
          return null;
        } else {
          phone = this.phoneUtil.format(phoneNumber, PhoneNumberFormat.E164);
          logger.debug(`Returning formatted phone ${phone}`);
          return phone;
        }
      case DataType.TIMESTAMP:
        const formattedTimestamp: number = moment.utc(value).valueOf(); // UNIX with mills
        return formattedTimestamp && !isNaN(formattedTimestamp) ? formattedTimestamp : null;
      default:
        logger.debug(`No compatible type so just returning raw value`); // should be impossible with Enum
        return value;
    }
  }
github jovotech / jovo-framework / examples / javascript / components / src / components / jovo-component-get-phone-number / src / handler.js View on Github external
function formatPhoneNumber(phoneNumber) {
    const phoneNumberE164 = phoneNumberUtilInstance.format(phoneNumber, PhoneNumberFormat.E164);
    return phoneNumberE164;
}
github celo-org / celo-monorepo / packages / utils / src / phoneNumbers.ts View on Github external
export function isE164NumberStrict(phoneNumber: string) {
  const parsedPhoneNumber = phoneUtil.parse(phoneNumber)
  if (!phoneUtil.isValidNumber(parsedPhoneNumber)) {
    return false
  }
  return phoneUtil.format(parsedPhoneNumber, PhoneNumberFormat.E164) === phoneNumber
}
github jovotech / jovo-framework / examples / typescript / components / src / components / GetPhoneNumber / src / handler.ts View on Github external
function formatPhoneNumber(phoneNumber: PhoneNumber) {
    const phoneNumberE164: string = phoneNumberUtilInstance.format(phoneNumber, PhoneNumberFormat.E164);

    return phoneNumberE164;
}
github betagouv / preuve-covoiturage / api / shared / providers / src / mongo / schemas / setters.js View on Github external
phone(v) {
    const number = phoneUtil.parseAndKeepRawInput(v, v.substr(0, 1) === '+' ? null : 'FR');

    if (!phoneUtil.isValidNumber(number)) {
      return v;
    }

    return phoneUtil.format(number, PhoneNumberFormat.E164);
  },
  iban(v) {
github miparnisari / arg.js / src / phone.js View on Github external
return clean(areaCode + national, 'AR');
        }
        else
          throw "Unknown area code for " + targetPhone;
      }
      else if (national[0] != '9') {
        return clean('+549' + national, 'AR');
      }
    }
  }
  catch (error) {
    throw "Can't parse number " + targetPhone + ": " + error;
  }

  if (tel) {
    return phoneUtil.format(tel, PNF.E164);
  }
  else {
    throw "Unknown error."
  }
};