1

I have a textarea inside my web, and the idea is that the user can write HTML code there. So then I would like to "validate" that code and confirm to the user that it's OK.

Maybe this could be done with jQuery? But I've only seen form validation. I want to validate any type of HTML code.

Thanks!

Paweł Bejger
  • 6,176
  • 21
  • 26
  • What do you mean with validate? Just that it has to be valid code, or you want to sanitize the HTML entered? – Andrea Parodi Feb 01 '14 at 21:26
  • I would suggest posting the textarea value to the server (_using Ajax_) and validate the markup there. What language do you use server-side? – Ram Feb 01 '14 at 21:29
  • I just want to check if the sintax is ok. I can do it using Ajax, I use PHP on my server, but the problem is the same, how will I validate that on PHP? – user3261420 Feb 01 '14 at 21:33
  • I use [HTMLPurifier](http://htmlpurifier.org/). – Ram Feb 01 '14 at 21:38
  • http://stackoverflow.com/a/1732454/3189029 – Will Feb 02 '14 at 00:29

2 Answers2

0

Take a look at https://github.com/peterjwest/html_validator. I think, something like this is what you are looking for.

It is a html parser library written in js.

Nagendra Rao
  • 7,016
  • 5
  • 54
  • 92
0

If you need to validate html I would go for an online api. It seems that w3.org has an online api + there are libraries available in different languages to validate by w3.org standards. Information about the online w3.org api can be found here http://validator.w3.org/docs/api.html

W3.org validation is implemented in different languages:

WebService::Validator::HTML::W3C in Perl, by Struan Donald.

Services_W3C_HTMLValidator in PHP, a PEAR library by Brett Bieber.

C# library by María Eugenia Fernández Menéndez.

Java client by the ReXSL.com team.

Python library by Kazbek Byasov.

kasper Taeymans
  • 6,950
  • 5
  • 32
  • 51