JavaScript/jQuery: How can I extract phone numbers from a text string?

I need assistance with extracting phone numbers from a text string that may be empty or formatted in multiple ways. Here are a few variations I might encounter:

  • “Call: 04 27 52 12 87 Mobile: 07 67 11 06 87”
  • “Call: 04 27 52 12 87”
  • “Mobile: 07 67 11 06 87”

Additionally, another format could be used: (0039) 234786. The markers to look for are “Call:” and/or “Mobile:”. I’m storing these numbers in two separate variables, one for mobile and another for landline.

So far, I have experimented with split and indexOf methods but I suspect there’s a more effective approach. Could anyone provide some insights or recommendations?

Hey there! You might wanna try using regex for this. Regex can match patterns efficiently. Look for patterns like /\b\d{2} \d{2} \d{2} \d{2} \d{2}\b/ for French style numbers or /\(\d{4}\) \d{6}/ for other formats. It’s a bit tricky but super effctive! :blush: