Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3846200
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:21:41+00:00 2026-05-19T16:21:41+00:00

I am using following regex to convert digits into phone format. telephoneNumber = ‘1234567890’;

  • 0

I am using following regex to convert digits into phone format.

telephoneNumber = '1234567890';
var number = telephoneNumber.replace(/\D/g,''); 
newNumber = number.replace(/^(\d{3})(\d{3})(\d{4})$/, '($1)$2-$3'); // (123)456-7890

Problem is that if telephoneNumber.length is greater than 10 then it does nothing. I want to add extra digits in the end of the phone number.

For example:

change 1234567890 to (123)456-7890
change 1234567890111 to (123)456-7890111

What should I change in above regex.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T16:21:42+00:00Added an answer on May 19, 2026 at 4:21 pm

    Try changing the last line to this:
    newNumber = number.replace(/^(\d{3})(\d{3})(\d{4,})$/, '($1)$2-$3');

    I just added a comma after the \d{4 this tells it to take 4 or more digits.

    Also, I often use this site to test out my regex’s: http://gskinner.com/RegExr/ It’s VERY handy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had been using the following regex for US Phone Number validation, but discovered
I have to validate using regex decimal number between 00.00 to 35.35 with following
i am using following regex expression to replace query=query.replace(/[^a-zA-Z 0-9*?:.+-^_]+/g,'') But when my query
I'm trying to convert the following bash code into C++ using boost::iostreams: #!/usr/bin/bash (
I'm using the following regex to validate one of my models validates :login, :format
I am using following regex to validate date in format dd/mm/yyyy in php: preg_match(/([0-9]{2})\/([0-9]{2})\/([0-9]{4})/,
I am using the following regex to get the src value of the first
I'm using the following regex to validate password complexity: /^.*(?=.{6,12})(?=.*[0-9]{2})(?=.*[A-Z]{2})(?=.*[a-z]{2}).*$/ In a nutshell: 2
I'm matching the following strings: watermark=testing watermark=text-testing|position-24-50 watermark=text-testing|position-24-50|color-6aa6cc watermark=text-testing|position-24-50|color-6aa6cc|size-48 using the following regex: watermark=(text-\w+\|position-\d+-\d+\|color-([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\|size-\d+|text-\w+\|position-\d+-\d+\|color-([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})|text-\w+\|position-\d+-\d+|\w+)
Consider following string Some string with quotes and \pre-slashed\ quotes Using regex, I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.