Search in sources :

Example 11 with PhoneNumberUtil

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;
}
Also used : TextParameters(org.talend.dataquality.indicators.TextParameters) PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) PhoneNumber(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber) NumberParseException(com.google.i18n.phonenumbers.NumberParseException)

Example 12 with PhoneNumberUtil

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;
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) PhoneNumber(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber) NumberParseException(com.google.i18n.phonenumbers.NumberParseException)

Example 13 with PhoneNumberUtil

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)"));
}
Also used : PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) PhoneNumber(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber) NumberParseException(com.google.i18n.phonenumbers.NumberParseException)

Example 14 with PhoneNumberUtil

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)));
    }
}
Also used : PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) SuppressLint(android.annotation.SuppressLint)

Example 15 with PhoneNumberUtil

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]", "") : "");
}
Also used : PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) PhoneNumber(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber) NumberParseException(com.google.i18n.phonenumbers.NumberParseException)

Aggregations

PhoneNumberUtil (com.google.i18n.phonenumbers.PhoneNumberUtil)47 NumberParseException (com.google.i18n.phonenumbers.NumberParseException)34 PhoneNumber (com.google.i18n.phonenumbers.Phonenumber.PhoneNumber)23 Phonenumber (com.google.i18n.phonenumbers.Phonenumber)13 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)6 TextParameters (org.talend.dataquality.indicators.TextParameters)6 Locale (java.util.Locale)5 SuppressLint (android.annotation.SuppressLint)4 Nullable (androidx.annotation.Nullable)2 PhoneNumberOfflineGeocoder (com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder)2 RemoteLoginException (io.kamax.mxisd.exception.RemoteLoginException)2 IOException (java.io.IOException)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 HttpPost (org.apache.http.client.methods.HttpPost)2 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)2 GenericValue (org.apache.ofbiz.entity.GenericValue)2 SpannableString (android.text.SpannableString)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1