views:

23

answers:

2

I have a TextArea which allows the user to enter HTML, what I am now trying to do is to validate the users HTML to ensure it is XHTML.

Any ideas?

A: 

I would suggest using regular expressions. Start at this post here

I havent seen a jquery plugin that does exactly what you want itself, but i'm sure you can alter some existing validation.

Byron Cobb
*cough* http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454
fudgey
+3  A: 

You can use a DOM Parser to see if the content is XML.

See here.


SNIPPET:

if (window.DOMParser)
  {
  parser=new DOMParser();
  xmlDoc=parser.parseFromString(text,"text/xml");
  }
else // Internet Explorer
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async="false";
  xmlDoc.loadXML(text);
  } 
Topera