testing TextBox.Text for any html content

  • Thread starter Thread starter Andy B.
  • Start date Start date
A

Andy B.

I have some TextBoxes that doesn't allow any html content. Was wondering how
you check to see if there is any?
 
Andy said:
I have some TextBoxes that doesn't allow any html content. Was
wondering how you check to see if there is any?

Presumably you are looking for anything that could be considered as html
markup rather than genuine html?

If there is no reason for "<" to appear in the text, perhaps you could
simply check for that character, otherwise you could encode the text so that
it is irrelevant if any html appears in it because you'll have encoded it to
&lt;whatever&gt; and so on.

You could even check for what key is being pressed and trap < so it can't be
entered in the first place, but you would also have to check for pasted text
containing a <.

If this is for an ASP.NET app, then do remember to check again server-side.

Andrew
 
Has to be real html code. Anything fake is fine.

Andrew Morton said:
Presumably you are looking for anything that could be considered as html
markup rather than genuine html?

If there is no reason for "<" to appear in the text, perhaps you could
simply check for that character, otherwise you could encode the text so
that it is irrelevant if any html appears in it because you'll have
encoded it to &lt;whatever&gt; and so on.

You could even check for what key is being pressed and trap < so it can't
be entered in the first place, but you would also have to check for pasted
text containing a <.

If this is for an ASP.NET app, then do remember to check again
server-side.

Andrew
 
Back
Top