Format Phone Number in US phone format using JQuery

1523
Views
1
Answers

I get a list of phone numbers from the view model. I need them to display in US phone number format
like (123) 456-7890. Now I get all the numbers as 1234567890. Is there any jQuery plugin to format?

edit | flag
Sam Bells
Asked on: Jun 01, 2012 at 12:10AM

1 Answers

137
1
137

If you need to just display the phone numbers in a standard format then use this function

Input : 1234567890

 function (text) {
           
if (text != "" && text != null)
               
{
             
return text.replace(/(\d{3})(\d{3})(\d{4})/, "($1) $2-$3");
               
}
           
return;
       
};

Output:(123) 456-7890

edit | flag
Gokul A
Answered on: Jun 01, 2012 at 12:15AM

Post your Answer

Search

Welcome to Ask Amoeba!
This is 100% free and interactive site for sharing professional Questions and Answers, Opensource projects, Interview questions.
Learners, beginners, Experts stop and share your knowledge and ideas!

Browse Categories

Browse Tags