Case sensitivity

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
LVL 9
OBCTAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

negatyveCommented:
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
OBCTAuthor Commented:
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
negatyveCommented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

OBCTAuthor Commented:
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
negatyveCommented:
>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
OBCTAuthor Commented:
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
negatyveCommented:
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
OBCTAuthor Commented:
Now I've got all possible swear words blocked but now flash is entering a blank username into the database.
0
negatyveCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OBCTAuthor Commented:
negatyve, what would I do without you?
Cheers!

-OBCT
0
negatyveCommented:
:)

nega
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.