Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Case sensitivity

Posted on 2003-12-12
11
Medium Priority
?
199 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
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
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.
Suggested Courses

580 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