negative look ahead to exclude html tags
Posted
by Remoh
on Stack Overflow
See other posts from Stack Overflow
or by Remoh
Published on 2010-04-27T21:41:08Z
Indexed on
2010/04/27
21:43 UTC
Read the original article
Hit count: 175
regular-expressions
|regex
I'm trying to come up with a validation expression to prevent users from entering html or javascript tags into a comment box on a web page.
The following works fine for a single line of text:
^(?!.(<|>)).$
..but it won't allow any newline characters because of the dot(.). If I go with something like this:
^(?!.(<|>))(.|\s)$
it will allow multiple lines but the expression only matches '<' and '>' on the first line. I need it to match any line.
This works fine:
^[-_\s\d\w"'.,:;#/&\$\%\?!@+*\()]{0,4000}$
but it's ugly and I'm concerned that it's going to break for some users because it's a multi-lingual application.
Any ideas? Thanks!
© Stack Overflow or respective owner