• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Type for phone number?

 
Marshal
Posts: 67939
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You pass 01234567890 to the constructor and it works out how much of that is dialling code and how much local number. You pass Locale.USA, 2345678910 to the factory method and it parses the phone number into (234) 567 8910 and finds the UsaPhoneNumber subclass and returns an instance of it.
 
Campbell Ritchie
Marshal
Posts: 67939
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...And how do mobile numbers differ from landline numbers in USA?
 
Ranch Hand
Posts: 539
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, and what if the formatting also differs by the type - mobile or landline? USA may be the same, but assuming it's different.
 
Campbell Ritchie
Marshal
Posts: 67939
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write down what the format is, something like this:-

(0 two digits)space four digits space four digits

Similarly for all the formats you are actually going to use.
Work out how to get from this:-

(01234) 567 890

to

01234567890

I thikn you can do it very simply by putting the text into a StringBuilder and stripping all the non‑digit characters. You mighr wish to throw an exception if you remove anything other than punctuation and spaces. But this is your app; you will have to decide.
 
Sheriff
Posts: 6801
182
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:...And how do mobile numbers differ from landline numbers in USA?


I don't think there's any difference.
 
Sheriff
Posts: 14990
250
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no difference between mobile and land line phone numbers in the US as far as I know. All of the numbers I've ever seen have a three-digit area code and a seven-digit phone number.
 
Prasanna Raman
Ranch Hand
Posts: 539
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct, there is no difference, but I'm just trying to program for any country thay may have different formats! And see how I can make it work.
 
Campbell Ritchie
Marshal
Posts: 67939
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try UK; we have dialling codes with 3 4 5 or 6 digits, but all phone numbers start 0 and have ten more digits.
 
I'm a lumberjack and I'm okay, I sleep all night and work all day. Lumberjack ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!