Home   Best Sellers   Blogging   Coding & Design   Technology   SEO   Travel & living   Career   Videos   Tips   Online tools     
Home  »     »  JS function to convert string to US phone number format

JS function to convert string to US phone number format

Tuesday, March 1, 2011

Javascript function to change the string to US telephone number format

Eg: if input string is 0115463234 ,it will be converted to (011)546-3234

function toPhoneFormat( obj ){

for(i=0;i < val.length;i++){
formatedString+=') ';


Sample usage:
Function is called in the onBlur event

<input id="txtpersontel" type="text" name="persontel" maxlength="20" style="width:125px"
onblur="toPhoneFormat('txtpersontel')" >

Share this!

How to link to this page?
If you wish to link to this page from your website, simply Copy and paste the above HTML code to your web page. It will appear on your page as:
JS function to convert string to US phone number format.

comments powered by Disqus

This Weeks 7 Popular Posts

Subscribe to Recent Posts by Email
Stay connected to CROZOOM with regular Email notices of new Techie articles and IT Jobs. Updates will be delivered to your Inbox as soon as they are posted online.

Enter Your Email Address:  

Delivered by FeedBurner   RSS Feed

Search this Blog   

Urgent Openings for PHP trainees, Andriod / IOS developers and PHP developers in Kochi Trivandrum Calicut and Bangalore. Please Send Your updated resumes to recruit.vo@gmail.com   Read more »