0

Does anyone know of a RegularExpression Validator or website thats stops script and html tags being used in TextBoxes and TextAreas

Updated:

public static string RegexReplace(string strin, string strExp, string strReplace)
    {
        return Regex.Replace(strin, strExp, strReplace);
    }

    public static string RemoveHTML(string strText)
    {
        return RegexReplace(strText, "<[^>]*>", string.Empty);
    }
ONYX
  • 5,679
  • 15
  • 83
  • 146

1 Answers1

1

You're not going to prevent a user from inputting data in an input. You "could" use javascript, but then the user "could" disable javascript and do what they want.

You need to sanitize on the server side AFTER the user submits the data.

Check out the Microsoft AntiXSS Library, and even MarkDownSharp can do this (even if you're not actually using Markdown). Alternatively there's always the HtmlAgilityPack to parse HTML for you.

HtmlAgilityPack

PM> Install-Package HtmlAgilityPack

MarkDownSharp

PM> Install-Package MarkdownSharp

AntiXss

PM> Install-Package AntiXSS

Do not, I repeat DO NOT parse html with regular expressions!!!!

Community
  • 1
  • 1
Chase Florell
  • 46,378
  • 57
  • 186
  • 376