470,648 Members | 1,672 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,648 developers. It's quick & easy.

Preventing people from entering HTML in textarea

Hi,

I have a text area and I want prevent people from entering HTML text
in the text area.

Someone putting "</textarea></tr><img
src="http://www.xxx.com/images/pic.gif">" in the textarea will
manipulate the page if the page was revisited.

Does anyone have any ideas?

Thanks in advance

Angela
Jul 20 '05 #1
3 1419
Angela wrote on 05 mrt 2004 in comp.lang.javascript:
I have a text area and I want prevent people from entering HTML text
in the text area.

Someone putting "</textarea></tr><img
src="http://www.xxx.com/images/pic.gif">" in the textarea will
manipulate the page if the page was revisited.


only if you reenter that string from serverside,
so that asks for a serverside solution,
depending on your server language.

clientside it could be done by:

onchange=
"this.value=this.value.replace(/</g,"&lt;")

[not tested]

but clientside JS could be manipulated by a client too.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #2
I will be using ASP, so maybe I will have to use regExp to solve this
problem
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
Angela Lam wrote:
I will be using ASP, so maybe I will have to use regExp to solve this
problem


Remove all markup:
str = str.replace(/<\/?[^>]*>/g, " ");

Optionally Server.HTMLEncode the data.
--
Andrew Urquhart
- FAQ: http://jibbering.com/faq
- Archive: http://groups.google.com/groups?grou...ang.javascript
- Reply: www.andrewu.co.uk/about/contact/
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by Elroyskimms | last post: by
5 posts views Thread by www.douglassdavis.com | last post: by
5 posts views Thread by Schraalhans Keukenmeester | last post: by
12 posts views Thread by MikeB | last post: by
reply views Thread by warner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.