This question already has an answer here:
How do I check if what was written in the textarea by the user is valid HTML? It could be with either PHP or Javascript.
</div>
This question already has an answer here:
How do I check if what was written in the textarea by the user is valid HTML? It could be with either PHP or Javascript.
</div>
In php, it would be quite simple:
if($text!=htmlspecialchars($text))
{
echo 'This contains HTML tags!!';
}
Of course, this means an ampersand would be valid, so you could also do something like
function hasHtml($string) {
if ( $string != strip_tags($string) )
return true;
}
You can use John Resig's html parser for the Javascript solution, or do something like this:
function is_html(string)
{
return string.match("/<[^<]+>/").length != 0;
}