Skip to main content

Posts

Showing posts from 2008

TelephoneNumber - Java class

The TelephoneNumber class was designed to use the java.text.MessageFormat class to format a US phone number with the proper characters and spacing. The class excepts numbers any many different ways and parses them into it's internal data so that it can display the phone number in the standard way, i.e. (800) 555-1212. It can even accept an alpha number like "877 HOLY-COW" and with the right options format it as alpha or numbers. The TelephoneNumber class represents a US telephone number. This class contains many constructors for various uses. It then stores the telephone number internally in seperate codes (area code, exchange, etc.). This encourages use of the format method to output the telephone number in any style the programmer wishes. [needs i18n work] Example usage: long number = 8005551212L; TelephoneNumber phone = new TelephoneNumber(number); StringBuffer msg = new StringBuffer("Call me at "); msg.append(phon