Solved

Case sensitivity

Posted on 2003-12-12
11
196 Views
Last Modified: 2010-04-03
I am using an XML file to generate an array to block out certain words. The problem I am having is that my input box is case sensitive, so if in my array I have blocked out the word "food", the user can type "Food" and it wont show up as a blocked word.
How can I get around this without adding in every possible case combination?

Cheers

-OBCT
0
Comment
Question by:OBCT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 27

Expert Comment

by:negatyve
ID: 9934187
Just verify if:

(word_from_xml.toLowerCase() == input_box.toLowerCase())

in flash 5, or:

(word_from_xml.toLowerCase() == input_box.text.toLowerCase())

in flash mx (using textfield instance  name)

If the condition is verified, show it as a blocked word...

[I think that the way it works is pretty clear.. :) ]
0
 
LVL 9

Author Comment

by:OBCT
ID: 9934262
I am using this in a user registration frame, so I don't want the users name of choise to end up in lower case if they used one or more upper case letters.
Is there any way I can run a loop on the array to set all posible combinations of the blocked word?
For example, just to make things more clear, I would like these to be blocked "food", "FOOD", "FoOd" etc but if a user types in "My User Name", I don't want it to end up as "my user name".
Sorry for making things complicated.

Cheers

-OBCT
0
 
LVL 27

Expert Comment

by:negatyve
ID: 9935951
maybe I don't understand the exact issue, but this condition:

(word_from_xml.toLowerCase() == input_box.toLowerCase())

doesn't change users name of choise in it's lower case version, it just check if the lower case version of that name is equal to the lower case version of the blocked name, meaning that you block every combination. For example:

• you want to block "food" word
• users type "FoOd"
• the condition is verified, because "FoOd".toLowerCase() and "food".toLowerCase() are equal, and the name is rejected
• users type "FOOd"
• the condition is verified, because "FOOd".toLowerCase() and "food".toLowerCase() are equal, and the name is rejected
• users type "DrINk"
• the condition is not verified, because "DrINk".toLowerCase() and "food".toLowerCase() are not equal, and "DrINk" is accepted as a good name, not "drink"...

is that what you want?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 9

Author Comment

by:OBCT
ID: 9936218
So how do I add this into my code?
I am using alot of if statements so I'd like to use the same style
Would I use something like this:
if (swearArray[n].toLowerCase() == username.toLowerCase()) {
     status = "Blocked word";
} else {
     //code here
0
 
LVL 27

Expert Comment

by:negatyve
ID: 9936337
>Would I use something like this:

yep.

suppose you are using an xml file like this:

=====================================
<?xml version="1.0" encoding="UTF-8"?>
<blockedwords>
      <word value="food" />
      <word value="drink" />
      <word value="pasta" />
      <word value="salad" />
</blockedwords>
=====================================

and suppose to load it with this code:
=====================================
data_xml = new XML();
data_xml.ignoreWhite = true;
data_xml.path = this;
data_xml.onLoad = function(success)
{
      if(success){
            var nodes = this.firstChild.childNodes;
            this.path.blockedWords = [];
            for(var i = 0; i < nodes.length; i++){
                  this.path.blockedWords.push(nodes[i].attributes.value);
            }
      } else {
            trace("XML FILE MISSING");
      }
};
data_xml.load("blockedwords.xml");
=====================================

by this time, you have in the same timeline where the script lies an array called "blockedWords", containing the external list. something like:

blockedWords = [];
blockedWords[0] = "food";
blockedWords[1] = "drink";
blockedWords[2] = "pasta";
blockedWords[3] = "salad";


to check for blocked word define a function like this:
=====================================
function isValidUserName(name)
{
      for(var i = 0; i < blockedWords.length; i++){
            if(name.toLowerCase() == blockedWords[i].toLowerCase()){
                  return false;
            }
      }
      return true;
}
=====================================


and to use it:
=====================================
if(isValidUserName(username)){
      // it's valid
      status = "YEAH";
      newUserName = username; // it is the original one, cases as typed by user
} else {
      // it's blocked
      status = "Blocked word";
}
=====================================
0
 
LVL 9

Author Comment

by:OBCT
ID: 9936532
I can't seem to get my code working. I don't know what I am doing wrong. If you have time, please take a look.
Cheers

swearXML = new XML();
swearXML.load("http://www.ddfhsdfg.com/scripts/xml/swearArray.xml");
swearXML.ignoreWhite = true;
swearXML.onLoad = processXML;
function processXML()
{
     swearArray = new Array();
     for (var n = 0; n<swearXML.firstChild.childNodes.length; n++)
       {
          swearArray[n] = swearXML.childNodes[0].childNodes[n].childNodes[0];
     }
}

combo_cb.setEnabled(false);
data_xml = new XML();
data_xml.ignoreWhite = true;
data_xml.path = this;
data_xml.onLoad = function(ok)
{
     this.path.combo_cb.setEnabled(true);
     if (ok)
       {
          var nodes = this.firstChild.childNodes;
          for (var i = 0; i < nodes.length; i++)
              {
               this.path.combo_cb.addItem(nodes[i].attributes.label, nodes[i].attributes.data);
          }
          this.path.combo_cb.setChangeHandler("changeData");
          this.path.changeData(combo_cb);
     }
       else
       {
          this.path.combo_cb.addItem("no data found");
          this.path.combo_cb.setEnabled(false);
     }
};
function changeData(_cb)
{
     this.newUser = _cb.getSelectedItem().data;
}
data_xml.load("http://www.dfgdsfgdsfgdsfg.com/scripts/xml/combodata.xml");

combo_cb2.setEnabled(false);
data2_xml = new XML();
data2_xml.ignoreWhite = true;
data2_xml.path = this;
data2_xml.onLoad = function(ok)
{
     this.path.combo_cb2.setEnabled(true);
     if (ok)
       {
          var nodes = this.firstChild.childNodes;
          for (var i = 0; i < nodes.length; i++)
              {
               this.path.combo_cb2.addItem(nodes[i].attributes.label, nodes[i].attributes.data);
          }
          this.path.combo_cb2.setChangeHandler("changeData");
          this.path.changeData(combo_cb2);
     }
       else
       {
          this.path.combo_cb2.addItem("no data found");
          this.path.combo_cb2.setEnabled(false);
     }
};
function changeData(_cb2)
{
     this.newUser = _cb2.getSelectedItem().data;
}
data2_xml.load("http://www.dfgsdfsg.com/scripts/xml/combodata2.xml");

function isValidUserName(name)
{
     for(var n = 0; n < swearArray.length; n++){
          if(username.toLowerCase() == swearArray[n].toLowerCase()){
               return false;
          }
     }
     return true;
}

submitBTN.onRelease = function()
{
      if(isValidUserName(username))
      {
          status = "YEAH";
            newUserName = username;
            
            if (!this._parent.username.length)
            {
              this._parent.status = "Please enter a username";
           }
             else
             {
          if (!this._parent.email.length ||
               this._parent.email.indexOf("@") == -1 ||
               this._parent.email.indexOf(".") == -1 ||
               this._parent.email.indexOf("com") == -1)
              {
               this._parent.status = "Please enter a valid email";
          }
              else
              {
               if (this._parent.email.length < 7)
                     {
                    this._parent.status = "Please enter a valid email";
               }
                     else
                     {
                    this._parent.status = "Loading...Please wait...";
                    this._parent.newUser = new LoadVars();
                    this._parent.newUser.path = this._parent;
                    this._parent.newUser.newUserName = this._parent.newUserName;
                    this._parent.newUser.email = this._parent.email;
                              this._parent.newUser.sex = this._parent.combo_cb2.getSelectedItem().data;
                    this._parent.newUser.timeZone = this._parent.combo_cb.getSelectedItem().data;
                    this._parent.newUser.onLoad = function(success)
                    {
                               if (success)
                               {
                                    if (this.result == "0")
                                    {
                                          status = "Complete"
                                          gotoAndStop("New User", 10)
                                    }
                                    else if (this.result == "3")
                                    {
                                          _root.gotoAndStop("Login", 30)
                                    }
                                    else if (this.result == "2")
                                    {
                                          status = "Username taken"
                                    }
                                    else if (this.result == "1")
                                    {
                                          status = "Email in use"
                                     }
                                    
                                    }
                    };
                              this._parent.newUser.sendAndLoad("http://www.fagsgadg.com/scripts/register.php", this._parent.newUser, "POST");
                        }
                  }
            }
      }
      else
      {
            status = "Blocked word";
      }
};
0
 
LVL 27

Expert Comment

by:negatyve
ID: 9936977
on thing at the time. if your xml file has got this structure:

<?xml version="1.0" encoding="UTF-8"?>
<blockedwords>
      <word>food</word>
      <word>drink</word>
</blockedwords>

you have to load it this way:

==========================================================================
swearXML = new XML();
swearXML.ignoreWhite = true;
swearXML.onLoad = processXML;
function processXML()
{
      swearArray = new Array();
      for (var n = 0; n < swearXML.firstChild.childNodes.length; n++) {
            // WRONG: swearArray[n] = swearXML.childNodes[0].childNodes[n].childNodes[0];
            swearArray[n] = swearXML.childNodes[0].childNodes[n].childNodes[0].nodeValue;
      }
}
swearXML.load("swearArray.xml");
==========================================================================
0
 
LVL 9

Author Comment

by:OBCT
ID: 9937086
Now I've got all possible swear words blocked but now flash is entering a blank username into the database.
0
 
LVL 27

Accepted Solution

by:
negatyve earned 500 total points
ID: 9937347
Well, I used "newUserName" to show you that you could create even a new variable, but maybe you should change you script to:

submitBTN.onRelease = function()
{
      if (isValidUserName(username)) {
            status = "YEAH";
            if (!this._parent.username.length) {
                  this._parent.status = "Please enter a username";
            } else {
                  if (!this._parent.email.length || this._parent.email.indexOf("@") == -1 || this._parent.email.indexOf(".") == -1 || this._parent.email.indexOf("com") == -1) {
                        this._parent.status = "Please enter a valid email";
                  } else {
                        if (this._parent.email.length < 7) {
                              this._parent.status = "Please enter a valid email";
                        } else {
                              this._parent.status = "Loading...Please wait...";
                              this._parent.newUser = new LoadVars();
                              this._parent.newUser.path = this._parent;
                              // USE USERNAME: YOU SERVER SHOULD BE WAITING FOR "USERNAME", NOT "NEW USERNAME"
                              this._parent.newUser.username = username
                              this._parent.newUser.email = this._parent.email;
                              this._parent.newUser.sex = this._parent.combo_cb2.getSelectedItem().data;
                              this._parent.newUser.timeZone = this._parent.combo_cb.getSelectedItem().data;
                              this._parent.newUser.onLoad = function(success)
                              {
                                    if (success) {
                                          if (this.result == "0") {
                                                status = "Complete";
                                                gotoAndStop("New User", 10);
                                          } else if (this.result == "3") {
                                                _root.gotoAndStop("Login", 30);
                                          } else if (this.result == "2") {
                                                status = "Username taken";
                                          } else if (this.result == "1") {
                                                status = "Email in use";
                                          }
                                    }
                              };
                              this._parent.newUser.sendAndLoad("http://www.fagsgadg.com/scripts/register.php", this._parent.newUser, "POST");
                        }
                  }
            }
      } else {
            status = "Blocked word";
      }
};
0
 
LVL 9

Author Comment

by:OBCT
ID: 9937367
negatyve, what would I do without you?
Cheers!

-OBCT
0
 
LVL 27

Expert Comment

by:negatyve
ID: 9937370
:)

nega
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question