Utility Function A Day.

I have a little plan to release a small code snippet a day till I run out or get bored 😉 Just simple little utility functions that do things like check phone numbers, credit cards etc. Nothing special but just handy to have a list around!

Heres the first:
Does the string contain Html?

/// <summary>
/// Does the string contain Html markup
/// </summary>
/// <param name="text">String to check</param>
/// <returns>True if markup is found</returns>
public static bool ContainsHtml(string value)
{
      Regex reg = new Regex(@"</?\w+((\s+\w+(\s*=\s*(?:"".*?""|'.*?'|[^'"">\s]+))?)+\s*|\s*)/?>", RegexOptions.None);
      return reg.IsMatch(value);
}

Please feel free to add any improvements in the comments 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *