JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/themes/ui-lightness/jquery-ui.css">
18005551212 1.800.555.1212 1-800-555-1212 (800) 555-1212 8005551212 800-555-1212 800.555.1212 5551212 555-1212 555.1212 2-800-555-1212 55-51212 551212 15551212
JavaScript
function callOutToCSharp(stringParameter){alert(stringParameter.toLocaleString());} window.onload = function() { var regex = /((\([0-9]{3}\) |[0-9]{3}-)[0-9]{3}-[0-9]{4})/, replacement = '<input type="button" value="$1" onclick="callOutToCSharp(\'launchPhoneCall:$1\');" />'; function replaceText(el) { if (el.nodeType === 3) { if (regex.test(el.data)) { var temp_div = document.createElement('div'); temp_div.innerHTML = el.data.replace(regex, replacement); var nodes = temp_div.childNodes; while (nodes[0]) { el.parentNode.insertBefore(nodes[0],el); } el.parentNode.removeChild(el); } } else if (el.nodeType === 1) { for (var i = 0; i < el.childNodes.length; i++) { replaceText(el.childNodes[i]); } }} replaceText(document.body); }