473,771 Members | 2,372 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

6 New Member
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

Expand|Select|Wrap|Line Numbers
  1. Regex regExp = new Regex("^[a-zA-Z_]*$");
  2.             string subject = tbxSubject.Text;
  3.             string comment = tbxComments.Text;
  4.             string username = Request.QueryString["Username"];
  5.             string datePosted = Common.InsertTodayIntoCommentsDate();
  6.             bool status = CommentClass.InsertComment(comment, username, datePosted, subject);
  7.  
  8.             if (regExp.IsMatch(status.ToString()))
  9.             {
  10.                 lblStatus.Text = "Comment added successfully.";
  11.                 lblStatus.ForeColor = System.Drawing.Color.Blue;
  12.             }
  13.             else
  14.             {
  15.                 lblStatus.Text = "Comment failed to add!!!.";
  16.                 lblStatus.ForeColor = System.Drawing.Color.Red;
  17.             }
Dec 9 '12 #1
3 2138
Rabbit
12,516 Recognized Expert Moderator MVP
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?
Dec 9 '12 #2
TearX
6 New Member
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
Dec 9 '12 #3
Rabbit
12,516 Recognized Expert Moderator MVP
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.
Dec 9 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
6859
by: Brian W | last post by:
Hi All, I have a web user control that, among other things, provides Print this page, and Email this page functionality I have this script that is to execute on the click of the asp:hyperlinks I have a function in a <SCRIPT> block that I want in the <head></head> section of the page. Unfortunately, RegisterClientScriptBlock, RegisterStartupScript don't always work, and when they do the script is placed inside the <form> tag (this...
3
2664
by: jsh02_nova | last post by:
Anybody know how to add a script block to the html <head> section programmatically without using the 'RegisterScriptBlock' functions? -- thx -jsh
0
1131
by: pealy2 | last post by:
A quick pointer to anyone struggling with the RegisterClientScriptBlock function, unless you already have a <FORM> section in your page then the script will not be added. I use vb code to generate all my visual objects on a page and it took me ages to work out why it wouldn't work on that page. The simple solution is to manually add a <FORM> </FORM> section to your page (I found a page which did have the section to see where to put it) ...
7
3519
by: Peter Jansson | last post by:
Dear group, I have been struggling to get a simple program for inserting and extracting std::tm objects to/from streams to work. The code below tries to read a std::tm object from a std::istringstream but fails to do so, could anybody see what is wrong with the code? (Output follows the code.) I fear that I have not completely grasped how the time_getXXX methods should be used in the operator<< ? With best regards,
13
27507
by: Davo | last post by:
Hi Folks, There seems to be something about not using tables for layout, but use divs instead. I'm not sure if I've got this right. If the output looks like what you want, then it shouldn't matter what tags you use I would have thought, or am I missing something? tia, Davo
9
2694
by: Zootal | last post by:
The following code will compile. I have one line commented out because it won't compile. Why can I not do this: //set<string>::iterator iterator = s->begin(); Why do I have to deference the set when I receive it as a pointer? Is that just the way we are supposed to do it, or am I missing something? -------------------------------------------------
4
4863
by: almurph | last post by:
Hi everyone, I'm a newbie to javascript. I have written some code to detect when a user presses the down-arrow, up-arrow and enter button. Essentially the user can arrow down or up through a list and the textbox is populated with the option when the user presses the enter button. This is for a VB.NET Web form type project. The problem is that when I press the enter button the entire form get
1
2334
by: widevision7 | last post by:
I have a web page that uses the following JavaScript to hide a <div> unless the checkbox is checked: <script type="text/javascript"> function showMe (it, box) { var vis = (box.checked) ? "block" : "none\ document.getElementById(it).style.display = vis; } I need to have it where if the box is not checked with 10 seconds, then a <meta refresh> is initiated, and the user is redirected to another page.
1
3736
by: Chinsu | last post by:
<html> <head> <style> #ex { width: 700px; background: red; float: left; } a, span { display: block;
0
9619
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10103
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9911
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8934
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.