Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes HTML, CSS and JavaScript and the fly likes how do i restrict HTML tags in textarea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how do i restrict HTML tags in textarea" Watch "how do i restrict HTML tags in textarea" New topic
Author

how do i restrict HTML tags in textarea

Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 753
How do i restrict HTML and other scripts tags in textbox or textarea ?

i mean user can write HTML and other tags like [html] abc [/html]
but in out put there should be no effect.

the effect should be like

System.out.println("mymethod1()");

o/p

mymethod1()
[ December 12, 2006: Message edited by: Jigar Naik ]

Jigar Naik


Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Look for HTML control characters (IE: <, >, &) and either escape them or reject the post and send the user an error message.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 753
how do we go thru individual character of a textarea ???
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

How are you retrieving the form fields now?
Post your the servlet or JSP code that you're using.
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 753
String s1 = req.getParameter("field_textarea");

I want to use java script but i m new to java script.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

OK, this forum is for JSP (server side).

To do what I mentioned earlier, look at Java's String object.
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html
It has several methods for replacing characters and substrings.

Javascript is a client side technology (interpreted in the user's browser).
We have an HTML/Javascript forum where these technologies are discussed.
If you would like this thread to be move to that forum, let me know and I will move it for you.
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 753
Yes i want all that validation stuff to be done on client side and thats you i maintaned java script.

please move this topic to the right place.

thanks a lot.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You STILL have to do it on the server

onsubmit of the form you can do replace(/</gi,"<") and so on.

Eric
 
jQuery in Action, 2nd edition
 
subject: how do i restrict HTML tags in textarea
 
Similar Threads
line height
Help Please!!!
Saffari browser does not support the html content on textarea
Saffari does not support html content on textarea
trouble with textarea