如何使用jquery/javascript在字符串中查找htmltag? [英] How to find a htmltag in a string using jquery/javascript?

查看:121
本文介绍了如何使用jquery/javascript在字符串中查找htmltag?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面中有一个文本区域.如果用户尝试提供一些html标签作为输入并提交,那么我需要抛出一个错误.

I have a text area in a page. If user try to give some html tags as a input and submit then i need to throw an error.

如何使用jquery/javascript完成此操作?

How can i get this done using jquery/javascript?

有人可以帮我吗?

推荐答案

上面评论中给出的答复不考虑下面的html标签.

Reply given in the above comment is not considering below html tags.

<html>,<body> and <head>

所以这就是我实施要求的方法,它工作正常.

So this is how i implemented the requirement and it is working fine.

var textboxValue = document.getElementById("textbox").value;
var nonHtmlValue = textboxValue.replace(/<[^>]+>/g, '');
if(textboxValue!=nonHtmlValue)
{
    alert("HTML is not allowed");
}

这篇关于如何使用jquery/javascript在字符串中查找htmltag?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆