开发者

Client side validation, Regext to match <script> tag,or how to validate blog post to prevent script posting

I was looking for regex to match script tag, i am using ASP.NET MVC 3.0 unobtrusive validation.

I found this regexp "^[<script (.|\n)?>(.|\n)*?</script>]*$" but i cant make it work properly, it is mating not only script tags for some rason.

How to fix that?

here is some examples:

1)

<script>
alert("a");
</script>
<div style="clear:both"><br /></div>

2)

<script src="/anypath" type="text/javasc开发者_StackOverflow中文版ript">antything
</script>
<div style="clear:both"><br /></div>

3)

<div style="clear:both"><br /></div>
<script>

</script>

What I ma trying to do - a want to validate blog post input to prevent post scripts as a part of blog post.


I think you would match script tags with a simpler regex:

(<script.*?>.*?</script>)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜