This week's book giveaway is in the JavaScript forum.
We're giving away four copies of JavaScript Promises Essentials and have Rami Sarieddine on-line!
See this thread for details.
The moose likes Struts and the fly likes phone number formatter in struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "phone number formatter in struts2" Watch "phone number formatter in struts2" New topic
Author

phone number formatter in struts2

Sandeep Kumar.
Greenhorn

Joined: Jul 23, 2008
Posts: 9
Hi

I have to display a phone number in (xxx)xxx-xxx format while i'm getting the phone number from the db as a 10 digit number(e.g. - 1324527865)

There are a lot of example on formatting date and numbers but no example on formatting strings(inserting comma,dot etc).

Any help will be much appreciated.




SCJP 6
Mike Cobelmach
Greenhorn

Joined: Jun 17, 2009
Posts: 19
You can use static method which convert string from database to your phone number format. More informations are in mail-archive.com.
Roberto Hernandez
Ranch Hand

Joined: Apr 29, 2009
Posts: 33
If you have a string, the best thing to do is to create a method that uses Java String Manipulation to convert to the format you want. In this case, you'll have to insert a parenthesis ( at the first position, ) at the third position and/or a hyphen - at the 4th position (999) 999-999. It shouldn't be that complicated. Use google and you'll find some examples
Sandeep Kumar.
Greenhorn

Joined: Jul 23, 2008
Posts: 9
I could always write a java code for masking and unmasking phone number which is what i am doing for time being.

but i wanted to define some format in ResourceBundle (e.g. item.price={0,number,currency}) so that i don't have to do the conversion by myself every time.

struts uses java.text.MessageFormat class for formatting and i don't know how to use MessageFormat class for string formatting .

still waiting for help.......
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: phone number formatter in struts2