Java Code Examples for com.google.i18n.phonenumbers.PhoneNumberUtil#getRegionCodeForCountryCode()
The following examples show how to use
com.google.i18n.phonenumbers.PhoneNumberUtil#getRegionCodeForCountryCode() .
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: NumberViewState.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
public String getCountryDisplayName() { if (selectedCountryName != null) { return selectedCountryName; } PhoneNumberUtil util = PhoneNumberUtil.getInstance(); if (isValid()) { String actualCountry = getActualCountry(util, getE164Number()); if (actualCountry != null) { return actualCountry; } } String regionCode = util.getRegionCodeForCountryCode(countryCode); return PhoneNumberFormatter.getRegionDisplayName(regionCode); }
Example 2
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 3
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; }