I have a text box and need to validate that it is plain text does not contain html tags.
What is the best way to do it in .net
Bonus Question: How to do the same with javascript.
I have a text box and need to validate that it is plain text does not contain html tags.
What is the best way to do it in .net
Bonus Question: How to do the same with javascript.
This post provides a nice clean HTML removal method. It uses RegEx, so it could easily be adapted to JavaScript.
Why not escape/encode any html, you'll get 1001 different ways to detect html with RegEx's but most will be flawed in some way. If escaping is not an option then your best bet might be to put a RegEx tag on the question and into the title to attract some experts.
You could allow it to be entered, then before doing ANYTHING with the input, you could use the HttpServerUtility.HtmlEncode class that will convert it all, so that when you re-render it (like in a comment), it wont be the original HTML, but rather the encoded rendering of it.