Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery to validate HTML in a TextArea

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?

like image 472
Coppermill Avatar asked Aug 25 '10 11:08

Coppermill


Video Answer


1 Answers

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);
  } 
like image 135
Topera Avatar answered Oct 02 '22 22:10

Topera