How to use the google-libphonenumber.PhoneNumberFormat.INTERNATIONAL 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 jtorhoff / flier / src / components / auth / SendCode.tsx View on Github external
onInput(event: React.SyntheticEvent) {
        event.preventDefault();

        let phoneNumber = event.currentTarget.value as string;
        try {
            const phoneUtil = PhoneNumberUtil.getInstance();
            phoneNumber = phoneUtil.format(
                phoneUtil.parse(phoneNumber),
                PhoneNumberFormat.INTERNATIONAL);
        } catch (e) {
            // Ignore errors as we validate on submit
        }

        this.setState({
            phoneNumber: phoneNumber,
        });

        if (this.state.error) {
            this.validate(phoneNumber);
        }
    }
github jtorhoff / flier / src / components / main / ChatMessagesTypes / ContactMessage.tsx View on Github external
export const contactMessage = (contact: API.MessageMediaContact) => {
    const title = [contact.firstName.string, contact.lastName.string].join(" ");
    let phoneNumber = contact.phoneNumber.string;
    if (phoneNumber.startsWith("+")) {
        try {
            const phoneUtil = PhoneNumberUtil.getInstance();
            phoneNumber = phoneUtil.format(
                phoneUtil.parse(phoneNumber),
                PhoneNumberFormat.INTERNATIONAL);
        } catch (e) {
            // Ignore errors
        }
    }

    return (
        <div>
            <div>
                
            </div>
            <div>
                <span>
                    {
                        title
                    }
                </span></div></div>
github celo-org / celo-monorepo / packages / utils / src / phoneNumbers.ts View on Github external
function handleSpecialCasesForDisplay(parsedNumber: PhoneNumber, countryCode?: number) {
  switch (countryCode) {
    // Argentina
    // The Google lib formatter incorretly adds '15' to the nationally formatted number for Argentina
    // However '15' is only needed when calling a mobile from a landline
    case 54:
      return phoneUtil
        .format(parsedNumber, PhoneNumberFormat.INTERNATIONAL)
        .replace(/\+54(\s)?/, '')

    case 231:
      const formatted = phoneUtil.format(parsedNumber, PhoneNumberFormat.NATIONAL)
      return formatted && formatted[0] === '0' ? formatted.slice(1) : formatted

    default:
      return phoneUtil.format(parsedNumber, PhoneNumberFormat.NATIONAL)
  }
}
github theslip / react-bootstrap-intl-tel-input / src / index.js View on Github external
validateNumber (alpha2, phoneNumber) {
    if (alpha2) {
      const _alpha2 = alpha2 === 'unknown' ? '' : alpha2
      try {
        this.phoneUtil.parse(phoneNumber, _alpha2)
      } catch (e) {
        const { message } = e
        return this.formatValidation(false, message, this.mapErrorMessage(message), null, null)
      }
      const { validMessage } = this.props
      const parsed = this.phoneUtil.parse(phoneNumber, _alpha2)
      const valid = this.phoneUtil.isPossibleNumber(parsed)
      const intlPhoneNumber = this.phoneUtil.format(parsed, PhoneNumberFormat.INTERNATIONAL)
      return this.formatValidation(valid, '', valid ? validMessage : this.mapErrorMessage(), parsed, intlPhoneNumber)
    } else {
      const { callingCodeMessage } = this.props
      return this.formatValidation(false, '', callingCodeMessage, null, null)
    }
  }
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;