• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

fmt error phone number

 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I want to format a string value containing numeric value to a phone number format:

However, the following error is thrown :
In <parseNumber>, value attribute can not be parsed: "2145255656"

Please help.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A phone number really isn't a number, it is a String containing digits. The fmt:formatNumber tag uses the DecimalFormat class to generate the output, and there just is no way to convert a number or String into a phone number format using the DecimalFormat class.

For the code you presented here will assume the parenthesis means positive numbers and the dash will format negative numbers. Your output would be (2145255656)--. That is, if you get past the parse errors.

The parse error comes from an incompatible input value, possibly because the value in the variable contains quotes, or is not a Number, or can't be coerced into a Number.

The solution is to format the phone number as a String with the proper format in the data object before you try to receive it in the JSP. An example utility method for doing so might be:

Which is set up for US, local 10 digit phone calls in the form (123) 456-7890.

[ August 08, 2008: Message edited by: Steve Luke ]
[ August 08, 2008: Message edited by: Steve Luke ]
 
aditee sharma
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Steve.
I can write the utility method myself, but thanks for the kind effort.
I wonder why despite phone number being a common feature among the websites, we don't have a utility method along the lines of format Date ?
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by aditee sharma:
Thanks Steve.
I can write the utility method myself, but thanks for the kind effort.
I wonder why despite phone number being a common feature among the websites, we don't have a utility method along the lines of format Date ?



Would be nice, but there are so many variations on what a phone number includes that a simple Locale won't do the trick. You would end up with a pretty hefty library to cover everything (I think). Or you can let us schleps store the Phone Number as a String and display it in a way that makes sense to us...
reply
    Bookmark Topic Watch Topic
  • New Topic