disallow special chracter and list of words

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • newcoder10
    New Member
    • Dec 2009
    • 9

    disallow special chracter and list of words

    Hi All,

    I would like to know what's the best way to write function(global ) in asp.net c# Framework 2.0 to check for textbox in a form (i have about 80 textbox on one form and I have many forms and textarea
    and I have list of 90 ro 100 words and special chracter that I do not want user to enter. If they enter the item from the list of blocked word or character I want to give them error saying "this character or word in not allowed, please correct it"
    The site is getting many hits already so I want to make sure it's not going to slow down a lot. I want to give the message as soon as one of the word or special character listed is found and not want to continue checking further.

    e.g of block list word "abc","bbc","bb d","cbc","xbc", "~","^","'" . the list can change in the future.

    I am new to asp.net and appreciate any help.

    Thanks
    newcoder
  • sanjib65
    New Member
    • Nov 2009
    • 102

    #2
    Blocking Special character or words

    The simplest way that comes to my mind is using if/else constructor where you have to mention those charaters and words.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      I typically have a "Utils" class that just has a bunch of public static/shared methods that help me do things like print to a log etc.

      I seen no reason why you can't use such a class in your application to do validation. You can call these methods from anywhere in your application.

      -Frinny

      Comment

      • newcoder10
        New Member
        • Dec 2009
        • 9

        #4
        your are right. Honestly I am very new to this and I do not know how to right such a function. Any help in sarting to write this function would be great.

        Thanks

        Comment

        • semomaniz
          Recognized Expert New Member
          • Oct 2007
          • 210

          #5
          Create an array and store all the words inside the array. Then use a for each loop and do the validation rather than using if else statement. Also as Frinny stated create a utility class to do the validation, This makes code much cleaner and more oop.

          Comment

          • newcoder10
            New Member
            • Dec 2009
            • 9

            #6
            Hi semomaniz,

            I am new to this and I do not know how to create array. I searched all over the internet and I could not find one. I found a few that will replace the bad word or special character but I do not want to filter. I just want to give the message saying this word is not allowed. I just need someone to help me give an example and I will enter all the words.

            Thanks for your help

            Comment

            • semomaniz
              Recognized Expert New Member
              • Oct 2007
              • 210

              #7
              here is the utility class, you go to add more data and any other validation that you require. The isvalid method returns boolean and is used to validate the data. now on the button event you will validate the data if it returns false then display your desired error

              Code:
              using System;
              using System.Data;
              using System.Configuration;
              using System.Web;
              using System.Web.Security;
              using System.Web.UI;
              using System.Web.UI.WebControls;
              using System.Web.UI.WebControls.WebParts;
              using System.Web.UI.HtmlControls;
              using System.Collections;
              
              public class Utility
              {
              	//data member
              	private string _InputText;
              	
              	//constructor
                      public Utility() { }
              	public Utility(string datatovalidate)
              	{
              		this.ValidationText = datatovalidate;
              	}
              
              	//getter n setter
              	public string ValidationText
              	{
              		get { return _InputText; }
              		set { _InputText = value; }
              	}
              	
              	//method	
              	public bool IsValid()
              	{
              		bool result = false;
              		//creating ArrayList 
              		ArrayList mydata = new ArrayList();
              		
              		myData.Add("abc");
              		myData.Add("ggc"); 
              		//now add all the unwanted data here
              		
              		
              		foreach (string x in myData)
              		{
              			if ( x.Equals(this.ValidationText))
              			{
              				return result;
              			}
              			else
              			{
              				result = true;
              			}
              		}
              		return result;
              	}
              	
              }

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                @semomaniz:
                Since newcoder10 doesn't even know how to declare an array I don't think that your class is going to make sense to them.

                @newcoder10:
                You are going to have to do your part in learning the basics. Knowing how to declare an array is extremely basic..in fact I'm not even sure what tutorials would be good for you because most articles out there assume that you know things like how to declare an array, how to use if statements, and how to use loops. Another reason why I don't know where to point you to is because you haven't stated what programming language you're using to develop your sever side logic. Are you using C#? Are you using VB.NET?

                -Frinny

                Comment

                • newcoder10
                  New Member
                  • Dec 2009
                  • 9

                  #9
                  Hi semomaniz,

                  Thanks for your help. I will play with this. I reall appreciate the code.

                  Dear Frinny, Thanks for your comments I am doing my part in learning and appreciate your willingness to direct me to tutorial. BTW I did mentioned above "asp.net c# Framework 2.0 " Sorry if my english isn't that well.

                  Thanks again to all of you.

                  Comment

                  • Frinavale
                    Recognized Expert Expert
                    • Oct 2006
                    • 9749

                    #10
                    Sorry newcoder10... I was concentrating more on your problem and over looked that.

                    Just a sec and I'll find you some simple tutorials to help you learn C#.

                    -Frinny

                    Comment

                    • newcoder10
                      New Member
                      • Dec 2009
                      • 9

                      #11
                      Hi Frinny,

                      Please no need to apologize, I should be thankful to your comments and help. I am glad I found and joined the site. I am sure I will learn a lot from all you gurus.
                      Once again thanks a lot for your patience, for helping and directing me to right path.

                      Thanks again.

                      Comment

                      • Frinavale
                        Recognized Expert Expert
                        • Oct 2006
                        • 9749

                        #12
                        The best place to start learning anything about .NET is on the MSDN Library. You should be able to use the library's search option to find help on just about anything that you want to learn about. This resource is very powerful, it has articles on every topic and every control. I use it almost every day (especially when I'm doing research). I recommend bookmarking it and using it as your primary resource when doing any development in .NET

                        There are tutorials there on how to use Arrays in C#.

                        I also recommend that you check out:

                        It's important to understand the ASP.NET life cycle but first you need to understand the basics: arrays, logical conditional statements, classes and events.

                        **edit**
                        Ooo this one looks good too C# Programming Guide


                        -Frinny

                        Comment

                        • newcoder10
                          New Member
                          • Dec 2009
                          • 9

                          #13
                          Frinny,

                          Thanks again for all the help. I will try to limit asking basic questions and will read and research before posting.

                          Thanks alot.

                          Comment

                          • Frinavale
                            Recognized Expert Expert
                            • Oct 2006
                            • 9749

                            #14
                            :) If you need help understanding something feel free to ask too :)
                            It's easier to help you if you have some sort of starting point...like a chunk of code or something...as apposed to "how do I do validation", which could be a huge topic.

                            -Frinny

                            Comment

                            • newcoder10
                              New Member
                              • Dec 2009
                              • 9

                              #15
                              Hi semomaniz,

                              I created the class file and it looks ok. I had one error message about case on myData and I changed that it does not have any error, I am trying to call this method on click event and not sure how to do it.
                              Again I am sorry for asking this basic question.

                              Thanks

                              Comment

                              Working...