What about the vast majority of phone numbers that don't fit that format? My phone number is that length but formatting it that way would be completely wrong.
eg: before = 0299999999
should be after = (02) 9999 9999
or alternatively I might enter my phone number as
+61299999999 and how would you format that?
Just to add to Stephen's post. One thing that really p*ss*s me off about ecommerce is foreign suppliers with sites that will not accept a phone number in international format.
Yes, I understand those concerns however my business is confined to a very local area in southwest Florida. With a few exceptions, all of those responding will be here during the winter months and looking for my services prior to leaving the area during the hot summer months. I provide home watch services.
Guess my post was a little selfish in that I wasn't to concerned what other would be able or not able to learn from the answer. If there is one, it would help me but perhaps not you. Mostlikely you don't have a winter home in Southwest Florida.
Take a look at this Javascript to Format Phone A Number. It looks like it does what you want. This was just the first hit on a google search with the string "Javascript phone number format".