this function call

<span>• <%=userData.getPhone()%></span>

returns a phone # for ex. 8005551155

Need a suggestion on setting it up as 800-555-1155 when i do the call

10 Years
Discussion Span
Last Post by ~s.o.s~

whn u ll return in the form 800-555-1155, it will be a string... u have to convert the phn no (whether it is long or something else) to String.

return phnNo.substring(1,3) + "-" + phnNo.substring(4,6) + "-"  + phnNo.substring(7,10)

worked like a charm..i had to overlap the #'s though like this

return phone.substring(0,3) + "-" + phone.substring(3,6) + "-" + phone.substring(6,10);

but it worked...thanx


u can check the conditions too... if the number has 10 digits, count as us/canada phn no... if the number has 11 digits, starts with 1, drop first number.... if it is more or less than 10/11, thn a lot of stories... :P
one thing to mention: phone.substring(6,10) means 6th to 10th letter... if u give any number of 16 digits, it will ignore rest... if u want to format like us number for more than 11 digits, it will be simply phone.substring(6) -> which means all the letters after 6th letter.


uh, no.
All countries use 10 digit numbers, plus an optional country code :)

And then there's cellphone numbers which in many countries don't have an area code.

In other words, forget about "nice" formatting as it's just not going to work.


Look into the Locale class. By detecting the user locale, you can pick up the corresponding information from the properties file(eg. the phone number format).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.