I have a use case where I need to identify phone numbers in a string and convert them to a clickable link. Using an external library is out of scope currently.
Here is what I've done so far:
String: "This is my phone number - 1234567890" I can extract 1234567890 as a phone number using a regex pattern.
I now want to replace it in the original string, so this is what I did:
const string = "This is my phone number - 1234567890"
const number = "1234567890"
const newString = '<a href="#">' + number + '</a>'
number = number.replace(number, newString);
When I do this, instead of getting the phone number as a hyperlink, my output is like this:
This is my phone number - <a href="#">1234567890</a>
If I create my newString without quotes, like this
const newString = <a href="#">number</a>
my output is like this:
This is my phone number - [object Object]
How do I make this a clickable link?