HTML Rendering – Check if a string is Html
Determines whether a given string contains basic HTML content.
The function checks for the presence of common HTML elements such as “html”, “body”, “table”, “div”, “p”, etc. using a regular expression. It looks for matched opening and closing tags. If the input is null, empty, or contains no HTML-like structure, the function returns False.
VB
Public Function IsHtmlContent(input As String) As Boolean
If String.IsNullOrWhiteSpace(input) Then
Return False
End If
' Check basic HTML tags
Dim htmlPattern As String = "(?i)<(html|body|table|tr|td|h[1-6]|div|span|p|a|img|ul|ol|li|br|hr|th)[^>]*>.*<\/\1>"
Dim regex As New Regex(htmlPattern)
' Se trova almeno un match, è HTML
Return regex.IsMatch(input)
End Function