I want change numbers in my webpage, I do not want to break the HTML of the page. What is the right way?
I have read this answer: RegEx match open tags except XHTML self-contained tags
However there is a skype plugin that somehow replace numbers in webpage. How does it do that?
Here is my code:
var formats = '(xxx) xxx-xxxx|(xxx)xxx-xxxx|xxx-xxx-xxxx|xxx.xxx.xxxx|xxx xxx xxxx';
var str = '('+formats.replace(/([\(\)\+\-])/g, '\\$1').replace(/x/g,'\\d') + ')';
var r = RegExp(str,'g');
document.body.innerHTML=document.body.innerHTML.replace(r,'<a style="color:#07C !important; font-size:100% !important;" href="https://call.com/number=$1">$1</a>');
The issue I'm facing is that it mess with body tags attributes for example:
<a href="https://stackoverflow.com/a/4338544/1269037">validate phone numbers properly</a>
Is replaced with broken html:
<a href="https://stackoverflow.com/a/<a style=" color:#07c="" !important;="" font-size:100%="" !important;"="">4338544/1269</a>
and code arround is all messed up.
I think the RegEx pattern is not well defined