About using regex code to block word such as <b> when i press the submit and it will

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TearX
    New Member
    • Dec 2012
    • 6

    About using regex code to block word such as <b> when i press the submit and it will

    I trying to block word in a comment and when they press submit it detect that it contain word such as <b> or <i>

    i have written as this(below) somehow i was not able to block it

    Code:
    Regex regExp = new Regex("^[a-zA-Z_]*$");
                string subject = tbxSubject.Text;
                string comment = tbxComments.Text;
                string username = Request.QueryString["Username"];
                string datePosted = Common.InsertTodayIntoCommentsDate();
                bool status = CommentClass.InsertComment(comment, username, datePosted, subject);
    
                if (regExp.IsMatch(status.ToString()))
                {
                    lblStatus.Text = "Comment added successfully.";
                    lblStatus.ForeColor = System.Drawing.Color.Blue;
                }
                else
                {
                    lblStatus.Text = "Comment failed to add!!!.";
                    lblStatus.ForeColor = System.Drawing.Color.Red;
                }
    Last edited by Rabbit; Dec 9 '12, 08:16 AM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    There's nothing in your regex that indicates it's looking for <b> or <i>. But in any case, why not just use a replace to remove the unwanted tags instead?

    Comment

    • TearX
      New Member
      • Dec 2012
      • 6

      #3
      oh i see. Hence how do i write if i looking for <b> or <i>??
      I still new to C# as i just started only a few months ago. I also do not understand on how a replace to remove the unwanted tags?
      currently reading on the Faqs of posting a question

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        If you're just trying to remove the tags, there's no need for regex. You can just use the replace method of the string class. If you just want to find the matches, you need to format the regex correctly. If you don't know how to do that, you should look into a regex tutorial.

        Comment

        Working...