Hii,
I want to restrict the html entities like '<' , ">" , "&"
etc but it should ac开发者_JS百科cept '<' and '>' when i click on a button
from the javascript. Can anybody gives me the regular expression for that
Updated regex for all entities, including numeric...
Javascript like:
var StrippedStr = YourStrVar.replace (/&#{0,1}[a-z0-9]+;/ig, "");
will strip just about every non-numeric html entity.
.
UPDATE:
Based on comment:
"but i want to identify the specified string contains <"
.
You can test for entities with:
var HasEntity = /&#{0,1}[a-z0-9]+;/i. test (YourStrVar);
.
You can get a list of the entities with:
var ListOfEntities = YourStrVar.match (/&#{0,1}[a-z0-9]+;/ig);
for (var J=0; J < ListOfEntities.length; J++)
{
alert ('Entity ' + (J+1) + '= ' + ListOfEntities[J]);
}
maybe that?
function remove() {
var buffer = document.getElementById("parent").innerHTML;
buffer = buffer.replace(/'<'/, "");
buffer = buffer.replace(/'>'/, "");
buffer = buffer.replace(/'&'/, "");
document.getElementById("parent").innerHTML = buffer;
}
just adujst the id
精彩评论