I'm using an older version of Telerik's Editor control, and storing the text that's input in a SQL database, then displaying the HTML later. Is there any way in ASP.NET (2.0) to validate a string as being valid HTML before saving to my database? Thanks!
You could start here:
Or here (regexes):
Regular Expressions Library - entries tagged with "HTML"
Or here ;)
regexes can be slow and cpu intensive, W3C has an open source tool that you could use http://www.w3.org/QA/Tools/
The editor has a built-in validator dialog that connects to the online W3 tool to check the current content. You can see an example here - XHTML Validator example
Hmm - which version are you using ("older version" isn't terribly specific)?
In the .Net 1.1/2.0 versions (I think about version 3.x/4.x from 2004/2005) the editor API consisted of a read/write property Html
that allowed you to set the content as HTML, and also retrieve it for storing where ever, and a read only property Xhtml
that ensures the you get compliant, XML based content (there were also properties like SaveAsXhtml
to ensure that if you were writing back to the file, it would be in XHTML).
I appreciate that if your page is serving content to HTML 4.0 then you might have some issues with closed tags (<br />
, <img />
, etc).
Remember there's a difference between valid HTML and clean HTML.
I see that the current version no longer has an Xhtml
property, and that the Html
property is deprecated in favour of the Content
property, so I assume this is outputting valid Xhtml by default.