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

  • Home
  • SEARCH
  • 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 938613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:40:20+00:00 2026-05-15T21:40:20+00:00

Basically, the input field is just a string. People input their phone number in

  • 0

Basically, the input field is just a string. People input their phone number in various formats. I need a regular expression to find and convert those numbers into links.

Input examples:

(201) 555-1212
(201)555-1212
201-555-1212
555-1212

Here’s what I want:

<a href="tel:(201)555-1212">(201) 555-1212</a> - Notice the space is gone
<a href="tel:(201)555-1212">(201)555-1212</a>
<a href="tel:201-555-1212">201-555-1212</a>
<a href="tel:555-1212">555-1212</a>

I know it should be more robust than just removing spaces, but it is for an internal web site that my employees will be accessing from their iPhone. So, I’m willing to “just get it working.”

Here’s what I have so far in C# (which should show you how little I know about regular expressions):

strchk = Regex.Replace(strchk, @"\b([\d{3}\-\d{4}|\d{3}\-\d{3}\-\d{4}|\(\d{3}\)\d{3}\-\d{4}])\b", "<a href='tel:$&'>$&</a>", RegexOptions.IgnoreCase);

Can anyone help me by fixing this or suggesting a better way to do this?

EDIT:

Thanks everyone. Here’s what I’ve got so far:

strchk = Regex.Replace(strchk, @"\b(\d{3}[-\.\s]\d{3}[-\.\s]\d{4}|\(\d{3}\)\s*\d{3}[-\.\s]\d{4}|\d{3}[-\.\s]\d{4})\b", "<a href='tel:$1'>$1</a>", RegexOptions.IgnoreCase);

It is picking up just about everything EXCEPT those with (nnn) area codes, with or without spaces between it and the 7 digit number. It does pick up the 7 digit number and link it that way. However, if the area code is specified it doesn’t get matched. Any idea what I’m doing wrong?

Second Edit:

Got it working now. All I did was remove the \b from the start of the string.

  • 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-15T21:40:21+00:00Added an answer on May 15, 2026 at 9:40 pm

    Remove the [] and add \s* (zero or more whitespace characters) around each \-.

    Also, you don’t need to escape the -. (You can take out the \ from \-)

    Explanation: [abcA-Z] is a character group, which matches a, b, c, or any character between A and Z.
    It’s not what you’re trying to do.


    Edits

    In response to your updated regex:

    • Change [-\.\s] to [-\.\s]+ to match one or more of any of those characters (eg, a - with spaces around it)
    • The problem is that \b doesn’t match the boundary between a space and a (.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.