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

Re: Help returning '-' in a phone # 80 80

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)
Re: Help returning '-' in a phone # 80 80

thanks playa......let me try that out

Re: Help returning '-' in a phone # 80 80

wish u good luck

Re: Help returning '-' in a phone # 80 80

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

Re: Help returning '-' in a phone # 80 80

and now to hope you never get any phone number that's not a US number...

Re: Help returning '-' in a phone # 80 80

yeah....

Re: Help returning '-' in a phone # 80 80

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.

Re: Help returning '-' in a phone # 80 80

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.

Re: Help returning '-' in a phone # 80 80

is it? thn i know some exceptions... :P

Re: Help returning '-' in a phone # 80 80

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).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.