By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,652 Members | 1,441 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,652 IT Pros & Developers. It's quick & easy.

Block unwanted html tags in a textarea

P: 2
Can anyone offer advice on how to stop users entering html tags in the textarea part of a form ?
Aug 20 '09 #1
Share this Question
Share on Google+
2 Replies


Dormilich
Expert Mod 5K+
P: 8,639
you can use a RegExp to remove anything that looks like "<some_chars>" afterwards. you can also check, if the character entered is "<" or ">", although this will also trigger for "f(x) < f(x+dx)" or "I <-- running away".
Aug 20 '09 #2

P: 2
thanks for the reply Dormilich.

Ideally I want to pop an alert box if the textarea has the text href in it.

My javascript is poor but I got it to work with ..

Expand|Select|Wrap|Line Numbers
  1. if (objForm.faultReport.value.length >= 2)
  2.             {        
  3.                 var invalid  ="href";
  4.                 var strData = objForm.faultReport.value;
  5.  
  6.                 gb_val = strData.indexOf(invalid);
  7.  
  8.                 if(gb_val>0)
  9.                 {
  10.                 alert("illegal text in the Comments box\n Please re-enter text");
  11.                 return(false);
  12.                 }
  13.             }
Aug 20 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.