I want to write a javascript function to read all the email addresses and make it to link.
for example if it finds [email protected] replace it with <a href="mailto:[email protected]">[email protected]</a>.
I am using this:
document.body.innerHTML = document.body.innerHTML.replace(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi, <a href="mailto:$1">$1</a>'));
It work fine for simple email addresses.
But the problem is if the email address already in this format:
"<a href="mailto:[email protected]">[email protected]</a>"
Then It does not work. The output becomes wrong like this:
[email protected]">[email protected]
Please suggestive me any solution. So the function can work fine.
Or any other function to make the simple email a link and if the email is already in mailto: link form then do nothing.