Solved

Case sensitivity

Posted on 2003-12-12
11
194 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
  • 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

840 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