How to use the google-libphonenumber.Error 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 blockchain / bc-phone-number / src / js / libphonenumber.js View on Github external
var numberObj = phoneUtil.parseAndKeepRawInput(number, countryCode);
    return phoneUtil.isPossibleNumberWithReason(numberObj);
  } catch (e) {
    //console.log(e);

    // here I convert thrown errors into ValidationResult enums (if possible)
    if (e == libphonenumber.Error.INVALID_COUNTRY_CODE) {
      return libphonenumber.PhoneNumberUtil.ValidationResult.INVALID_COUNTRY_CODE;
    }
    if (e == libphonenumber.Error.NOT_A_NUMBER) {
      return 4;
    }
    if (e == libphonenumber.Error.TOO_SHORT_AFTER_IDD || e == libphonenumber.Error.TOO_SHORT_NSN) {
      return libphonenumber.PhoneNumberUtil.ValidationResult.TOO_SHORT;
    }
    if (e == libphonenumber.Error.TOO_LONG) {
      return libphonenumber.PhoneNumberUtil.ValidationResult.TOO_LONG;
    }

    // broken
    return -99;
  }
}
github blockchain / bc-phone-number / src / js / libphonenumber.js View on Github external
function getValidationError(number, countryCode) {
  try {
    var phoneUtil = libphonenumber.PhoneNumberUtil.getInstance();
    var numberObj = phoneUtil.parseAndKeepRawInput(number, countryCode);
    return phoneUtil.isPossibleNumberWithReason(numberObj);
  } catch (e) {
    //console.log(e);

    // here I convert thrown errors into ValidationResult enums (if possible)
    if (e == libphonenumber.Error.INVALID_COUNTRY_CODE) {
      return libphonenumber.PhoneNumberUtil.ValidationResult.INVALID_COUNTRY_CODE;
    }
    if (e == libphonenumber.Error.NOT_A_NUMBER) {
      return 4;
    }
    if (e == libphonenumber.Error.TOO_SHORT_AFTER_IDD || e == libphonenumber.Error.TOO_SHORT_NSN) {
      return libphonenumber.PhoneNumberUtil.ValidationResult.TOO_SHORT;
    }
    if (e == libphonenumber.Error.TOO_LONG) {
      return libphonenumber.PhoneNumberUtil.ValidationResult.TOO_LONG;
    }

    // broken
    return -99;
  }
}
github blockchain / bc-phone-number / src / js / libphonenumber.js View on Github external
function getValidationError(number, countryCode) {
  try {
    var phoneUtil = libphonenumber.PhoneNumberUtil.getInstance();
    var numberObj = phoneUtil.parseAndKeepRawInput(number, countryCode);
    return phoneUtil.isPossibleNumberWithReason(numberObj);
  } catch (e) {
    //console.log(e);

    // here I convert thrown errors into ValidationResult enums (if possible)
    if (e == libphonenumber.Error.INVALID_COUNTRY_CODE) {
      return libphonenumber.PhoneNumberUtil.ValidationResult.INVALID_COUNTRY_CODE;
    }
    if (e == libphonenumber.Error.NOT_A_NUMBER) {
      return 4;
    }
    if (e == libphonenumber.Error.TOO_SHORT_AFTER_IDD || e == libphonenumber.Error.TOO_SHORT_NSN) {
      return libphonenumber.PhoneNumberUtil.ValidationResult.TOO_SHORT;
    }
    if (e == libphonenumber.Error.TOO_LONG) {
      return libphonenumber.PhoneNumberUtil.ValidationResult.TOO_LONG;
    }

    // broken
    return -99;
  }
}
github blockchain / bc-phone-number / src / js / libphonenumber.js View on Github external
function getValidationError(number, countryCode) {
  try {
    var phoneUtil = libphonenumber.PhoneNumberUtil.getInstance();
    var numberObj = phoneUtil.parseAndKeepRawInput(number, countryCode);
    return phoneUtil.isPossibleNumberWithReason(numberObj);
  } catch (e) {
    //console.log(e);

    // here I convert thrown errors into ValidationResult enums (if possible)
    if (e == libphonenumber.Error.INVALID_COUNTRY_CODE) {
      return libphonenumber.PhoneNumberUtil.ValidationResult.INVALID_COUNTRY_CODE;
    }
    if (e == libphonenumber.Error.NOT_A_NUMBER) {
      return 4;
    }
    if (e == libphonenumber.Error.TOO_SHORT_AFTER_IDD || e == libphonenumber.Error.TOO_SHORT_NSN) {
      return libphonenumber.PhoneNumberUtil.ValidationResult.TOO_SHORT;
    }
    if (e == libphonenumber.Error.TOO_LONG) {
      return libphonenumber.PhoneNumberUtil.ValidationResult.TOO_LONG;
    }

    // broken
    return -99;
  }
}