Sunday, August 2, 2009

Regulare Expression to replace text in Javascript

function myreplace()
{
if (!document.body typeof(document.body.innerHTML) == "undefined")
{
if (warnOnFailure)
{
alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
}
return false;
}
var bodyText = document.body.innerHTML; //bodyText="123"; var
bodyText=bodyText.replace(/\d{3}-\d{3}-\d{3}/gi, "123-456-786");
bodyText=bodyText.replace(/\d{3}\.\d{3}\.\d{3}/gi, "123.456.787");
//alert(news);
document.body.innerHTML = bodyText;
}

No comments:

Post a Comment