I have an unformatted telephone number string ("5551234567"). I would like to format this string for display purposes in the ui. The number should look like this after format:
(555) 123-4567
Sigh.....
I was trying to find a generic way that would take into account both US and international phone numbers. I came accross the MaskFormatter in the JDK but discovered that there is a bug in the Javadoc. Which lead me to asking my question here. I was hoping for a solution where I could input a mask then the actual string. The output would be formatted accordingly for international/US numbers or if the wrong number of characters were specified, some default character would be displayed in place of the missing characters........
http://www.java.net/node/660119
String.format("(%s) %s-%s", number.substring(0, 3), number.substring(3, 6),
number.substring(6, 10));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With