How to check that asp: TextBox does not contain html tags

I have a textbox and need to check that it is plain text that does not contain html tags.

What is the best way to do this in .net

Bonus question: how to do the same with javascript.

0


source to share


2 answers


You can allow it to be injected, and then before doing ANYTHING with input, you can use the HttpServerUtility.HtmlEncode class that will convert it all so that when you re-render it (as in the comment) it won't be the original HTML, but rather encoded by rendering it ...



+1


source


Why not avoid / encode some html, you get 1001 ways to detect html with RegEx, but most of them will be incorrect. If escaping is not an option, the best option might be to put a RegEx tag in the question and in the title to attract some experts.



0


source







All Articles