use of com.google.i18n.phonenumbers.PhoneNumberUtil in project tdq-studio-se by Talend.
the class WellFormIntePhoneCountIndicatorImpl method handle.
@Override
public boolean handle(Object data) {
super.handle(data);
if (data == null) {
return false;
}
try {
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
IndicatorParameters indParameters = this.getParameters();
TextParameters textParameters = indParameters == null ? null : indParameters.getTextParameter();
String country = IndicatorHelper.getCountryCodeByParameter(textParameters);
PhoneNumber phoneNumeber = phoneUtil.parse(data.toString(), country);
String format = phoneUtil.format(phoneNumeber, PhoneNumberFormat.INTERNATIONAL);
if (data.toString().equals(format)) {
wellFormIntePhoneCount++;
if (checkMustStoreCurrentRow() || checkMustStoreCurrentRow(drillDownValueCount)) {
this.mustStoreRow = true;
}
}
} catch (NumberParseException e) {
return false;
}
return true;
}
use of com.google.i18n.phonenumbers.PhoneNumberUtil in project ofbiz-framework by apache.
the class UtilValidate method isValidPhoneNumber.
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;
}
use of com.google.i18n.phonenumbers.PhoneNumberUtil in project packages_apps_Contacts by AOKP.
the class PhoneNumberTestService method dump_PhoneNumberUtil_format.
private void dump_PhoneNumberUtil_format(String number, String country, PhoneNumberFormat format) {
String formatted;
String truncated = "";
boolean isValid = false;
try {
final PhoneNumberUtil util = PhoneNumberUtil.getInstance();
final PhoneNumber pn = util.parse(number, country);
isValid = util.isValidNumber(pn);
formatted = util.format(pn, format);
util.truncateTooLongNumber(pn);
truncated = util.format(pn, format);
} catch (NumberParseException e) {
formatted = "Error: " + e.toString();
}
Log.i(TAG, " PhoneNumberUtil.format(parse(" + number + ", " + country + "), " + format + ") = " + formatted + " / truncated = " + truncated + (isValid ? " (valid)" : " (invalid)"));
}
use of com.google.i18n.phonenumbers.PhoneNumberUtil in project Signal-Android by WhisperSystems.
the class DeleteAccountFragment method handleRegionUpdated.
private void handleRegionUpdated(@Nullable String regionCode) {
PhoneNumberUtil util = PhoneNumberUtil.getInstance();
countryFormatter = regionCode != null ? util.getAsYouTypeFormatter(regionCode) : null;
reformatText(number.getText());
if (!TextUtils.isEmpty(regionCode) && !"ZZ".equals(regionCode)) {
number.requestFocus();
int numberLength = number.getText().length();
number.getInput().setSelection(numberLength, numberLength);
countryCode.setText(String.valueOf(util.getCountryCodeForRegion(regionCode)));
}
}
use of com.google.i18n.phonenumbers.PhoneNumberUtil in project Signal-Android by WhisperSystems.
the class PhoneNumberFormatter method formatE164.
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 != null ? number.replaceAll("[^0-9]", "") : "");
}
Aggregations