admin管理员组文章数量:1335594
Hii,
I want to restrict the html entities like '<' , ">" , "&"
etc but it should accept '<' and '>' when i click on a button
from the javascript. Can anybody gives me the regular expression for that
Hii,
I want to restrict the html entities like '<' , ">" , "&"
etc but it should accept '<' and '>' when i click on a button
from the javascript. Can anybody gives me the regular expression for that
-
How about
©
,〹
,ꯍ
and ordinal text likefoo
? Do you just want to strip HTML tags like<script>
?<b>
? – kennytm Commented Jun 25, 2010 at 6:54 - No i want accept all the html tags but if it the content is in the encodeed format that should be avoided – Jibu P C_Adoor Commented Jun 25, 2010 at 6:56
-
So you want to reject the input if there's
<
? – kennytm Commented Jun 25, 2010 at 7:01 - exactly,but should not reject '<' or '>' – Jibu P C_Adoor Commented Jun 25, 2010 at 7:05
2 Answers
Reset to default 11Updated 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 ment:
"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
本文标签: regexRegular expression in javascript for restricting HTML entites like ampltStack Overflow
版权声明:本文标题:regex - Regular expression in javascript for restricting HTML entites like &lt; - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742393191a2466397.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论