0

I know there are some similar questions out there, but I haven't been able to successfully adapt the code I've seen from similar questions.

Perhaps the big difference is that I'm not trying to search actual text nodes in the DOM, but I am storing strings in an object. I have a listings object which I am populating with data from a classified listings API. So I want to take each listings[i].body property, use a regular expression to find any telephone numbers, and then wrap them with <a href="tel:x">. This same data will then be used to populate Google Maps Markers and Info Windows.

Community
  • 1
  • 1
minttoothpick
  • 75
  • 2
  • 11
  • 2
    is your code confidential!you need to show us the code you have tried.. – Anirudha Dec 11 '12 at 19:03
  • 1
    You also haven't asked a question… :) – anotherdave Dec 11 '12 at 19:04
  • This is a question I asked for C#, but you should be able to easily translate it to JavaScript: http://stackoverflow.com/questions/3302482/i-need-a-regular-expression-to-convert-us-tel-number-to-link – BoltBait Dec 11 '12 at 19:19
  • Thanks @BoltBait, I hadn't come across your question because I was filtering by "JavaScript," but the solution to your question helped me out! – minttoothpick Dec 11 '12 at 19:54
  • Solution: iterate through `listings`, then for each listing, `listing.body = listing.body.replace(/(\d{3}[-\.\s]\d{3}[-\.\s]\d{4}|\(\d{3}\)\s*\d{3}[-\.\s]\d{4}|\d{3}[-\.\s]\d{4})\b/g, "$1");` – minttoothpick Dec 11 '12 at 19:56
  • 1
    Edit your original post and update it with code instead of pasting it in the comments. – Jack Dec 11 '12 at 20:43

0 Answers0