Boris Smirnov
Boris Smirnov

Reputation: 1257

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

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.

Upvotes: 0

Views: 1779

Answers (2)

Mark
Mark

Reputation: 14950

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.

Upvotes: 1

Dan Powley
Dan Powley

Reputation: 743

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.

Upvotes: 0

Related Questions