?
Solved

Case sensitivity

Posted on 2003-12-12
11
Medium Priority
?
197 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
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…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
Suggested Courses

770 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