Com.google.i18n.phonenumbers Error?

As far as I know, BRAZIL COUNTRY CODE +55

But this piece of code

mobilePhoneNumber = "+32495665962";
            isoCode = "BR";

            phoneNumber = phoneNumberUtil.parse(mobilePhoneNumber, isoCode);
            isValid = phoneNumberUtil.isValidNumber(phoneNumber);
            phoneNumberType = phoneNumberUtil.getNumberType(phoneNumber);

            System.out.println ("phoneNumber ----- > " + phoneNumber);
            System.out.println ("isValid --------- > " + isValid);
            System.out.println ("phoneNumberType - > " + phoneNumberType);

      

gives me this number as valid!

phoneNumber ----- > Country Code: 32 National Number: 495665962
isValid --------- > true
phoneNumberType - > MOBILE

      

+3


source to share


2 answers


Read the Javadoc :

defaultRegion

is the area from which we expect the number to be. This is only used if the number being processed is not written in international format . The country code for the number in this case will be stored as the default region number. If the number is guaranteed to start with a "+" followed by a country dialing code, then either "ZZ" or "null" can be specified.



Your login is in international form, so this parameter is not used.

Why do you expect the library to convert a phone number from Belgium to Brazil?

+3


source


libphonenumber

isValidNumber(...)

will return true if this number is valid anywhere. For example, what you enter is a valid Belgium number. I believe you are using this incorrectly. What do you want to use for isValidNumberForRegion(Phonenumber.PhoneNumber number, String regionCode)

.



See https://javadoc.io/doc/com.googlecode.libphonenumber/libphonenumber/8.5.0

+1


source







All Articles