LearnFast.Ninja

How to build HTML not allowed module in ASP.NET C#

This tutorial will show you in short how to restrict Html elements in text the user submitted. When you build comments module and you want to prevent spam in your site you can restrict the users to enter only text. We call that "HTML Not Allowed".

C# code:

string Comment = "Comment text here";

if (Regex.Match(Comment, @"<(.|\n)*?>").Success == true)

{

    return "HTML Not Allowed";

}


JavaScript code:

function Is_Success(result) {

    if (result == "HTML Not Allowed") {

        alert(result);

    }


Result:


Tags

asp.net

regex match regular-expression