com.google.i18n.phonenumbers.NumberParseException Java Examples
The following examples show how to use
com.google.i18n.phonenumbers.NumberParseException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PhoneNumberFormatter.java From libsignal-service-java with GNU General Public License v3.0 | 6 votes |
public static String formatE164(String countryCode, String number) { try { PhoneNumberUtil util = PhoneNumberUtil.getInstance(); int parsedCountryCode = Integer.parseInt(countryCode); PhoneNumber parsedNumber = util.parse(number, util.getRegionCodeForCountryCode(parsedCountryCode)); return util.format(parsedNumber, PhoneNumberUtil.PhoneNumberFormat.E164); } catch (NumberParseException | NumberFormatException npe) { Log.w(TAG, npe); } return "+" + countryCode.replaceAll("[^0-9]", "").replaceAll("^0*", "") + number.replaceAll("[^0-9]", ""); }
Example #2
Source File: ShortCodeUtil.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
public static boolean isShortCode(@NonNull String localNumber, @NonNull String number) { try { PhoneNumberUtil util = PhoneNumberUtil.getInstance(); Phonenumber.PhoneNumber localNumberObject = util.parse(localNumber, null); String localCountryCode = util.getRegionCodeForNumber(localNumberObject); String bareNumber = number.replaceAll("[^0-9+]", ""); // libphonenumber seems incorrect for Russia and a few other countries with 4 digit short codes. if (bareNumber.length() <= 4 && !SHORT_COUNTRIES.contains(localCountryCode)) { return true; } Phonenumber.PhoneNumber shortCode = util.parse(number, localCountryCode); return ShortNumberInfo.getInstance().isPossibleShortNumberForRegion(shortCode, localCountryCode); } catch (NumberParseException e) { Log.w(TAG, e); return false; } }
Example #3
Source File: Util.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
@RequiresPermission(anyOf = { android.Manifest.permission.READ_PHONE_STATE, android.Manifest.permission.READ_SMS, android.Manifest.permission.READ_PHONE_NUMBERS }) @SuppressLint("MissingPermission") public static Optional<Phonenumber.PhoneNumber> getDeviceNumber(Context context) { try { final String localNumber = ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number(); final Optional<String> countryIso = getSimCountryIso(context); if (TextUtils.isEmpty(localNumber)) return Optional.absent(); if (!countryIso.isPresent()) return Optional.absent(); return Optional.fromNullable(PhoneNumberUtil.getInstance().parse(localNumber, countryIso.get())); } catch (NumberParseException e) { Log.w(TAG, e); return Optional.absent(); } }
Example #4
Source File: LookupAsyncTask.java From callerid-for-android with GNU General Public License v3.0 | 6 votes |
@Override protected void onPreExecute() throws Exception { super.onPreExecute(); address.setVisibility(View.GONE); if(layout.findViewById(R.id.map_view)!=null) layout.findViewById(R.id.map_view).setVisibility(View.GONE); image.setVisibility(View.VISIBLE); text.setVisibility(View.VISIBLE); final PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance(); try{ final PhoneNumber phoneNumberPhoneNumber = phoneNumberUtil.parse(phoneNumber.toString(), countryDetector.getCountry()); final PhoneNumberOfflineGeocoder phoneNumberOfflineGeocoder = PhoneNumberOfflineGeocoder.getInstance(); offlineGeocoderResult = phoneNumberOfflineGeocoder.getDescriptionForNumber(phoneNumberPhoneNumber, Locale.getDefault()); }catch(NumberParseException e){ //ignore this exception } if("".equals(offlineGeocoderResult)) offlineGeocoderResult = null; if(offlineGeocoderResult == null) text.setText(lookupInProgress); else text.setText(offlineGeocoderResult); image.spin(); }
Example #5
Source File: MobileValidation.java From keycloak-extension-playground with Apache License 2.0 | 6 votes |
static boolean isPhoneNumberValid(String phoneNumber) { String formattedPhoneNumber = convertInternationalPrefix(phoneNumber); String region; if (isPossibleNationalNumber(formattedPhoneNumber)) { region = "DE"; } else if (isInternationalNumber(formattedPhoneNumber)) { region = null; } else { return true; // If the number cannot be interpreted as an international or possible DE phone number, do not attempt to validate it. } try { Phonenumber.PhoneNumber parsedPhoneNumber = PhoneNumberUtil.getInstance().parse(formattedPhoneNumber, region); return PhoneNumberUtil.getInstance().isValidNumber(parsedPhoneNumber); } catch (NumberParseException e) { return false; } }
Example #6
Source File: Utilities.java From call_manage with MIT License | 6 votes |
/** * Format a given phone number to a readable string for the user * * @param phoneNumber the number to format * @return the formatted number */ public static String formatPhoneNumber(String phoneNumber) { if (phoneNumber == null) return null; phoneNumber = normalizePhoneNumber(phoneNumber); Phonenumber.PhoneNumber formattedNumber = null; PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); try { formattedNumber = phoneUtil.parse(phoneNumber, sLocale.getCountry()); } catch (NumberParseException e) { Timber.w(e); return phoneNumber; } PhoneNumberUtil.PhoneNumberFormat format; if (phoneUtil.getRegionCodeForCountryCode(formattedNumber.getCountryCode()).equals(sLocale.getCountry())) format = PhoneNumberUtil.PhoneNumberFormat.NATIONAL; else format = PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL; return phoneUtil.format(formattedNumber, format); }
Example #7
Source File: XMPPUtils.java From desktopclient-java with GNU General Public License v3.0 | 6 votes |
public static String phoneNumberToKontalkLocal(String number) { PhoneNumberUtil pnUtil = PhoneNumberUtil.getInstance(); PhoneNumber n; try { n = pnUtil.parse(number, null); } catch (NumberParseException ex) { return ""; } if (!pnUtil.isValidNumber(n)) return ""; return DigestUtils.sha1Hex( PhoneNumberUtil.getInstance().format(n, PhoneNumberUtil.PhoneNumberFormat.E164)); }
Example #8
Source File: E164PhoneNumberWithExtension.java From jadira with Apache License 2.0 | 6 votes |
/** * Returns the underlying LibPhoneNumber {@link Phonenumber.PhoneNumber} instance. * To preserve the immutability of E164PhoneNumber, a copy is made. * @return The underlying PhoneNumber instance */ public Phonenumber.PhoneNumber getUnderlyingPhoneNumber() { Phonenumber.PhoneNumber copy; StringBuilder e164Builder = new StringBuilder(); PHONE_NUMBER_UTIL.format(number, PhoneNumberFormat.E164, e164Builder); try { copy = PHONE_NUMBER_UTIL.parse(e164Builder.toString(), "GB"); } catch (NumberParseException e) { throw new PhoneNumberParseException( EX_PARSE_MSG_PREFIX + number.getNationalNumber() +"}", e); } if (number.hasExtension()) { copy.setExtension(number.getExtension()); } return copy; }
Example #9
Source File: PhoneUtil.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 6 votes |
@Override public PhoneNumber parsePhoneNumber(String numberText) { if (!StringUtils.isEmpty(numberText)) { if (numberText.startsWith("00")) { numberText = numberText.replaceFirst("00", "+"); } numberText = numberText.replaceAll("[^0-9+]",""); try { final PhoneNumber phoneNumber = PHONE_UTIL.parse(numberText, null); if (PHONE_UTIL.isValidNumber(phoneNumber)) { return phoneNumber; } } catch (NumberParseException e) { return null; } } return null; }
Example #10
Source File: E164PhoneNumberWithExtension.java From jadira with Apache License 2.0 | 6 votes |
/** * Creates a instance from the given PhoneNumber * @param prototype The PhoneNumber to construct the instance from */ public E164PhoneNumberWithExtension(Phonenumber.PhoneNumber prototype) { StringBuilder e164Builder = new StringBuilder(); PHONE_NUMBER_UTIL.format(prototype, PhoneNumberFormat.E164, e164Builder); try { this.number = PHONE_NUMBER_UTIL.parse(e164Builder.toString(), "GB"); } catch (NumberParseException e) { throw new PhoneNumberParseException( EX_PARSE_MSG_PREFIX + prototype.getNationalNumber() +"}", e); } if (prototype.hasExtension()) { this.number.setExtension(prototype.getExtension()); } }
Example #11
Source File: PhoneNumberFormatter.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
public static String formatE164(String countryCode, String number) { try { PhoneNumberUtil util = PhoneNumberUtil.getInstance(); int parsedCountryCode = Integer.parseInt(countryCode); PhoneNumber parsedNumber = util.parse(number, util.getRegionCodeForCountryCode(parsedCountryCode)); return util.format(parsedNumber, PhoneNumberUtil.PhoneNumberFormat.E164); } catch (NumberParseException | NumberFormatException npe) { Log.w(TAG, npe); } return "+" + countryCode.replaceAll("[^0-9]", "").replaceAll("^0*", "") + number.replaceAll("[^0-9]", ""); }
Example #12
Source File: E164PhoneNumberWithExtension.java From jadira with Apache License 2.0 | 6 votes |
/** * Creates a new E164 Phone Number with the given extension. * @param e164PhoneNumber The phone number in E164 format * @param extension The extension, or null for no extension */ protected E164PhoneNumberWithExtension(String e164PhoneNumber, String extension) { if (!e164PhoneNumber.startsWith("+")) { throw new PhoneNumberParseException("Only international numbers can be interpreted without a country code"); } try { number = PHONE_NUMBER_UTIL.parse(e164PhoneNumber, "GB"); } catch (NumberParseException e) { throw new PhoneNumberParseException( EX_PARSE_MSG_PREFIX + e164PhoneNumber +"}", e); } number.setExtension(extension); }
Example #13
Source File: MainActivity.java From Android with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance(); Phonenumber.PhoneNumber indianPhoneNumber = null; try { indianPhoneNumber = phoneNumberUtil.parse(phoneNumber, "IN"); boolean val = phoneNumberUtil.isValidNumber(indianPhoneNumber); Log.d("Parzival", "Data: "+indianPhoneNumber.getCountryCode()+" >> "+indianPhoneNumber.getNationalNumber()); Log.d("Parzival", "Val: "+val); } catch (NumberParseException e) { e.printStackTrace(); } }
Example #14
Source File: ContactFragment.java From customview-samples with Apache License 2.0 | 6 votes |
private void displayContactData(){ List<PhoneInfo> phoneInfoList = MobileContactSingleton.getInstance().getMobileContact(); PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); for(PhoneInfo phoneInfo: phoneInfoList) { try { String phoneNum = phoneInfo.getPhoneNum(); Phonenumber.PhoneNumber phoneNumProto = phoneUtil.parse(phoneNum, "CN"); boolean isValid = phoneUtil.isValidNumber(phoneNumProto); Log.d("hyh", "ContactFragment: displayContactData: isValid="+isValid+" ,phoneNum="+phoneNum); if (isValid) { String formatPhoneNum = phoneUtil.format(phoneNumProto, PhoneNumberUtil.PhoneNumberFormat.E164); Log.d("hyh", "ContactMgr: run: formatPhoneNum=" + formatPhoneNum); } } catch (NumberParseException e) { Log.d("hyh", "ContactFragment: displayContactData: phone="+phoneInfo.getPhoneNum()); e.printStackTrace(); } } ContactListAdapter contactListAdapter = new ContactListAdapter(getContext(),phoneInfoList); mRvContactList.setLayoutManager(new LinearLayoutManager(getContext())); mRvContactList.setAdapter(contactListAdapter); }
Example #15
Source File: BaseFlagFragment.java From android-phone-number-with-flags with Apache License 2.0 | 6 votes |
protected String validate() { String region = null; String phone = null; if (mLastEnteredPhone != null) { try { Phonenumber.PhoneNumber p = mPhoneNumberUtil.parse(mLastEnteredPhone, null); StringBuilder sb = new StringBuilder(16); sb.append('+').append(p.getCountryCode()).append(p.getNationalNumber()); phone = sb.toString(); region = mPhoneNumberUtil.getRegionCodeForNumber(p); } catch (NumberParseException ignore) { } } if (region != null) { return phone; } else { return null; } }
Example #16
Source File: PhoneUtils.java From android-phone-number-with-flags with Apache License 2.0 | 6 votes |
private static String parseNumber(String paramString) { if (paramString == null) { return null; } PhoneNumberUtil numberUtil = PhoneNumberUtil.getInstance(); String result; try { Phonenumber.PhoneNumber localPhoneNumber = numberUtil.parse(paramString, null); result = numberUtil.getRegionCodeForNumber(localPhoneNumber); if (result == null) { return null; } } catch (NumberParseException localNumberParseException) { return null; } return result; }
Example #17
Source File: SignIn.java From XERUNG with Apache License 2.0 | 6 votes |
private void sendOTPNumber(){ if(checkNull()){ PhoneNumberUtil util = PhoneNumberUtil.getInstance(); // assuming you only a button in your layout... boolean isAuthentic = false; try { PhoneNumber number = util.parse(countryPrefix + edtMobile.getText().toString().trim(), countryIso); isAuthentic = true; } catch (NumberParseException e) { e.printStackTrace(); } if (isAuthentic) { comman.hideSoftKeyBoard(context, edtMobile); createJson(edtMobile.getText().toString().trim(), countryPrefix, countryName); } } }
Example #18
Source File: PhoneValidator.java From sunbird-lms-service with MIT License | 6 votes |
public static boolean validatePhone(String phone, String countryCode) { PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance(); String code = countryCode; if (StringUtils.isNotBlank(countryCode) && (countryCode.charAt(0) != '+')) { code = "+" + countryCode; } Phonenumber.PhoneNumber phoneNumber = null; try { if (StringUtils.isBlank(countryCode)) { code = PropertiesCache.getInstance().getProperty("sunbird_default_country_code"); } String isoCode = phoneNumberUtil.getRegionCodeForCountryCode(Integer.parseInt(code)); phoneNumber = phoneNumberUtil.parse(phone, isoCode); return phoneNumberUtil.isValidNumber(phoneNumber); } catch (NumberParseException e) { ProjectLogger.log( "PhoneValidator:validatePhone: Exception occurred while validating phone number = ", e); } return false; }
Example #19
Source File: ProjectUtil.java From sunbird-lms-service with MIT License | 6 votes |
public static boolean validatePhone(String phNumber, String countryCode) { PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance(); String contryCode = countryCode; if (!StringUtils.isBlank(countryCode) && (countryCode.charAt(0) != '+')) { contryCode = "+" + countryCode; } Phonenumber.PhoneNumber phoneNumber = null; try { if (StringUtils.isBlank(countryCode)) { contryCode = PropertiesCache.getInstance().getProperty("sunbird_default_country_code"); } String isoCode = phoneNumberUtil.getRegionCodeForCountryCode(Integer.parseInt(contryCode)); phoneNumber = phoneNumberUtil.parse(phNumber, isoCode); return phoneNumberUtil.isValidNumber(phoneNumber); } catch (NumberParseException e) { ProjectLogger.log("Exception occurred while validating phone number : ", e); ProjectLogger.log(phNumber + "this phone no. is not a valid one."); } return false; }
Example #20
Source File: GoogleFirebaseAuthenticator.java From mxisd with GNU Affero General Public License v3.0 | 6 votes |
private void toMsisdn(BackendAuthResult result, String phoneNumber) { if (StringUtils.isBlank(phoneNumber)) { return; } try { String number = phoneUtil.format( phoneUtil.parse( phoneNumber, null // No default region ), PhoneNumberUtil.PhoneNumberFormat.E164 ).substring(1); // We want without the leading + result.withThreePid(new ThreePid(ThreePidMedium.PhoneNumber.getId(), number)); } catch (NumberParseException e) { log.warn("Invalid phone number: {}", phoneNumber); } }
Example #21
Source File: PhoneNumberFormatter.java From Silence with GNU General Public License v3.0 | 6 votes |
public static String formatE164(String countryCode, String number) { try { PhoneNumberUtil util = PhoneNumberUtil.getInstance(); int parsedCountryCode = Integer.parseInt(countryCode); PhoneNumber parsedNumber = util.parse(number, util.getRegionCodeForCountryCode(parsedCountryCode)); return util.format(parsedNumber, PhoneNumberUtil.PhoneNumberFormat.E164); } catch (NumberParseException | NumberFormatException npe) { Log.w(TAG, npe); } return "+" + countryCode.replaceAll("[^0-9]", "").replaceAll("^0*", "") + number.replaceAll("[^0-9]", ""); }
Example #22
Source File: AddressUtil.java From scipio-erp with Apache License 2.0 | 6 votes |
/** * Validates phone numbers (using external library). * <p> * SCIPIO: 2018-08-30: Stock method moved here from {@link org.ofbiz.base.util.UtilValidate} * due to dependency issues. */ public static boolean isValidPhoneNumber(String phoneNumber, String geoId, Delegator delegator) { boolean isValid = false; try { GenericValue geo = EntityQuery.use(delegator).from("Geo").where("geoId", geoId).cache().queryOne(); PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); String geoCode = geo != null ? geo.getString("geoCode") : "US"; PhoneNumber phNumber = phoneUtil.parse(phoneNumber, geoCode); if (phoneUtil.isValidNumber(phNumber) || phoneUtil.isPossibleNumber(phNumber)) { isValid = true; } } catch (GenericEntityException | NumberParseException ex) { Debug.logError(ex, module); } return isValid; }
Example #23
Source File: ExpandableAdvisoriesAdapter.java From AirMapSDK-Android with Apache License 2.0 | 6 votes |
private String formatPhoneNumber(Context context, String number) { if (TextUtils.isEmpty(number)) { return context.getString(R.string.no_known_number); } PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); Locale locale = Locale.getDefault(); String country = locale != null && locale.getCountry() != null && !TextUtils.isEmpty(locale.getCountry()) ? locale.getCountry() : "US"; try { Phonenumber.PhoneNumber phoneNumber = phoneUtil.parse(number, country); return phoneUtil.format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL); } catch (NumberParseException e) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return PhoneNumberUtils.formatNumber(number, country); } return PhoneNumberUtils.formatNumber(number); } }
Example #24
Source File: UiUtils.java From tindroid with Apache License 2.0 | 6 votes |
static Credential parseCredential(String cred) { final PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); final String country = Locale.getDefault().getCountry(); if (Patterns.PHONE.matcher(cred).matches()) { // Looks like a phone number. try { // Normalize phone number format cred = phoneUtil.format(phoneUtil.parse(cred, country), PhoneNumberUtil.PhoneNumberFormat.E164); // Exception not thrown, we have a phone number. return new Credential(Credential.METH_PHONE, cred); } catch (NumberParseException ignored) { return null; } } // Not a phone number. Try parsing as email. if (Patterns.EMAIL_ADDRESS.matcher(cred).matches()) { return new Credential(Credential.METH_EMAIL, cred); } return null; }
Example #25
Source File: ShortCodeUtil.java From Silence with GNU General Public License v3.0 | 6 votes |
public static boolean isShortCode(@NonNull String localNumber, @NonNull String number) { try { PhoneNumberUtil util = PhoneNumberUtil.getInstance(); Phonenumber.PhoneNumber localNumberObject = util.parse(localNumber, null); String localCountryCode = util.getRegionCodeForNumber(localNumberObject); String bareNumber = number.replaceAll("[^0-9+]", ""); // libphonenumber doesn't seem to be correct for Germany and Finland if (bareNumber.length() <= 6 && ("DE".equals(localCountryCode) || "FI".equals(localCountryCode) || "SK".equals(localCountryCode))) { return true; } // libphonenumber seems incorrect for Russia and a few other countries with 4 digit short codes. if (bareNumber.length() <= 4 && !SHORT_COUNTRIES.contains(localCountryCode)) { return true; } Phonenumber.PhoneNumber shortCode = util.parse(number, localCountryCode); return ShortNumberInfo.getInstance().isPossibleShortNumberForRegion(shortCode, localCountryCode); } catch (NumberParseException e) { Log.w(TAG, e); return false; } }
Example #26
Source File: AutoInitiate.java From Silence with GNU General Public License v3.0 | 6 votes |
public static boolean isTaggableDestination(Recipients recipients){ // Be safe - err on the side of not tagging if (recipients.isGroupRecipient()) return false; PhoneNumberUtil util = PhoneNumberUtil.getInstance(); try { PhoneNumber num = util.parse(recipients.getPrimaryRecipient().getNumber(), Locale.getDefault().getCountry()); PhoneNumberType type = util.getNumberType(num); Log.d(TAG, "Number type: " + type.toString()); return type == PhoneNumberType.FIXED_LINE || type == PhoneNumberType.MOBILE || type == PhoneNumberType.FIXED_LINE_OR_MOBILE; } catch (NumberParseException e){ Log.w(TAG, "Couldn't get number type (country: " + Locale.getDefault().getCountry() + ")"); return false; } }
Example #27
Source File: MainPresenter.java From YaMvp with MIT License | 6 votes |
private String validateThenFormatMobileNumber(String phone) { try { PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance(); Phonenumber.PhoneNumber phoneNumber = phoneNumberUtil.parse(phone, "+86"); if (phoneNumberUtil.isValidNumber(phoneNumber) && ( phoneNumberUtil.getNumberType(phoneNumber) == PhoneNumberUtil.PhoneNumberType.MOBILE || phoneNumberUtil.getNumberType(phoneNumber) == PhoneNumberUtil.PhoneNumberType.FIXED_LINE_OR_MOBILE)) { return phoneNumberUtil.format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.E164); } else { return ""; } } catch (NumberParseException e) { return ""; } }
Example #28
Source File: SignIn.java From XERUNG with Apache License 2.0 | 6 votes |
private void sendOTPNumber(){ if(checkNull()){ PhoneNumberUtil util = PhoneNumberUtil.getInstance(); // assuming you only a button in your layout... boolean isAuthentic = false; try { PhoneNumber number = util.parse(countryPrefix + edtMobile.getText().toString().trim(), countryIso); isAuthentic = true; } catch (NumberParseException e) { e.printStackTrace(); } if (isAuthentic) { comman.hideSoftKeyBoard(context, edtMobile); createJson(edtMobile.getText().toString().trim(), countryPrefix, countryName); } } }
Example #29
Source File: E164PhoneNumberWithExtension.java From jadira with Apache License 2.0 | 5 votes |
/** * Creates a new E164 Phone Number. * @param phoneNumber The phone number in arbitrary parseable format (may be a national format) * @param defaultCountryCode The Country to apply if no country is indicated by the phone number */ protected E164PhoneNumberWithExtension(String phoneNumber, CountryCode defaultCountryCode) { try { number = PHONE_NUMBER_UTIL.parse(phoneNumber, defaultCountryCode.toString()); } catch (NumberParseException e) { throw new PhoneNumberParseException( EX_PARSE_MSG_PREFIX + phoneNumber + "} for country {" + defaultCountryCode +"}", e); } }
Example #30
Source File: E164PhoneNumberWithExtension.java From jadira with Apache License 2.0 | 5 votes |
/** * Creates a new E164 Phone Number with the given extension. * @param phoneNumber The phone number in arbitrary parseable format (may be a national format) * @param extension The extension, or null for no extension * @param defaultCountryCode The Country to apply if no country is indicated by the phone number */ protected E164PhoneNumberWithExtension(String phoneNumber, String extension, CountryCode defaultCountryCode) { try { number = PHONE_NUMBER_UTIL.parse(phoneNumber, defaultCountryCode.toString()); } catch (NumberParseException e) { throw new PhoneNumberParseException( EX_PARSE_MSG_PREFIX + phoneNumber + "} for country {" + defaultCountryCode +"}", e); } if (extension != null) { number.setExtension(extension); } }