I would like to check if a given string has a correct html syntax. I don't know which html elements should be inside, the only one thing I know is that string should be a correct html expression.
Anyone has an idea how to check it in C#?
test. bind(/(<([^>]+)>)/i); It will basically return true for strings containing a < followed by ANYTHING followed by > .
The W3C MarkUp Validator: This looks at the (X)HTML doctype you are using for the document you give it to check, and then checks your markup accordingly. This is the one we recommend if you are using an HTML4 or XHTML1. x doctype. It does validate HTML5, but validator.nu is arguably more up to date.
test with "<p>fizz buzz</p>" to check if "<p>fizz buzz</p>" is a JavaScript string. We use <\/?[a-z][\s\S]*> to check for any tags in the string to check if it has any HTML markup.
You can use Html Agility Pack : http://html-agility-pack.net/?z=codeplex
string html = "<span>Hello world</sspan>"; HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); if (doc.ParseErrors.Count() > 0) { //Invalid HTML }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With