This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Struts and the fly likes filter out html tag in user input using validator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "filter out html tag in user input using validator" Watch "filter out html tag in user input using validator" New topic
Author

filter out html tag in user input using validator

Ningfeng Xu
Greenhorn

Joined: Jan 22, 2002
Posts: 18
hi, how can I filter out html tag in user input in validator?

I used the following code(this code actually is for the opposite case, say, true if the input has "<xxx>" substring. The reason is so far I don't know how to write the desired regular expression, "not-<xxx>"):

<var><var-name>mask</var-name><var-value>^<[^<>]+>$</var-value></var>

But the validator reports error, saying this is not well-formatted. I know the problem is "<" in "<[^<>]+>". I tried the unicode of "<", as the following, no error reported any more, but still not working(can't validate true if input has html tag:
<var><var-name>mask</var-name><var-value>^\u003c[^\u003c>]+>$</var-value></var>

Any one can help?

Thanks.


SCJP2
Ningfeng Xu
Greenhorn

Joined: Jan 22, 2002
Posts: 18


I solved this issue, as the following:

<![CDATA[ ^[^<]*[^>]*$ ]]>

This is not a strong solution, to detect html tags in user input, but so far good enough for me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: filter out html tag in user input using validator
 
Similar Threads
custom validation not working
Form bean validator
Mask Validation
Validator Issue with multiply beans
Validator for NOT NULL/ blanks