Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6660525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:09:58+00:00 2026-05-26T02:09:58+00:00

I think I’m facing a paradox here. What I’m trying to do is when

  • 0

I think I’m facing a paradox here.

What I’m trying to do is when I receive/make a call, I have the number, so I need to know if its an international number, if its a local number, etc.

The problem is:

  1. For me to know if a number is international, I need to parse it and check its length, but, the length differs from country to country, so, should I do a method that parses and recognizes for each country? (Unfunctional in my opinion);
  2. For me to know if its a local number, I need the area code, so I have to make the same thing, parse the number and check the lenght, get the first numbers based on the area code lenght;

Its kinda hard to find the solution for this. The library libphonenumber offers a lot of usefull classes, but the one that I thought that could help me, took me to another paradox.

The method phoneUtil.parse(number, countryAcronym) returns the number with its country code, but what it does is, if I pass the number with the acronym “US” it return the number with country code ‘1’, now if I change the acronym to “BR” it changes the number and return ’55’ that is the country code for Brazil. So, anyways, I need the country acronym based on the number I get.

EX:

numberReturned = phoneUtil.parse(phoneNumber, "US");
phoneUtil.format(numberReturned, PhoneNumberFormat.INTERNATIONAL);

The above code, returns the number with the US country code but now if I change the “US” to any other country acronym it will return the same number but with the country code of that country.

I know that this lib is not supposed to guess from which country the number is (THAT WOULD BE AWESOME!!), but thats what I need.

This is really making my mind goes crazy. I need good advices from the wise mages of SO.

If you please could help me with a good decision, I’d be so thankfull.

Thanks.


PS: If you already use libphonenumber and has more experience with this, please guide me on which class to use, if there is one capable of solving this problem. =)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:09:58+00:00Added an answer on May 26, 2026 at 2:09 am

    1) The second parameter to phoneUtil.parse must match the country you’re currently in – it’s used if the phone number received does not include an international prefix. That’s why you get different results when you change the parameter: the phone number you pass it does not contain such a prefix, so it just uses what you’ve told it.

    Any parsing solution set to determine if the phone number is international or not will need to be aware of this: depending on the source, even a national number may be represented with the international dialing prefix (usually abstracted as +, since it differs between countries, but this is not guaranteed).

    2) For area code parsing, there is no universal standard; some countries don’t use them, and even within a country, area codes may have differing lengths (e.g. Germany). I’m not aware of an international library for this – and a quick search doesn’t find anything (though that doesn’t mean one does not exist). You might need to roll your own here; if you only need to support a single country, this shouldn’t be too hard.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think its called a slice... basically I have a list of lists: [['fmt/10',
I think most people know how to do this via the GUI (right click
I think most people here understand the importance of fully automated builds. The problem
I think I know how to handle this case, but I just want to
Think Windows Explorer's 'Details' view. I need to output my database to this view.
I think I have found a bug when setting or getting the Me.Top property
I think firefox's support to box model in CSS3 is soooooooooooooo poor... I have
Think about the classic installation process, where you have a next button and when
Think 2 entities OneToOne mapped. Person and Car. A Person can have a Car.
Think that I have many activities,and all I want is this: I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.