Download

Can you give me correct usage of ActionScript restrict to prevent use of illegal characters?

I’m trying to use TextField - Adobe ActionScript® 3 (AS3 ) API Reference to block input of illegal characters, but I can’t get it to work. I’m trying both of these:



textInput.restrict = "^\"";


and also



textInput.textField.restrict = "^\"";


Both compile just fine, but neither prevents the player from inputting " into the field. Can someone give me the correct usage for restricting characters in a GFx TextInput? Thanks.

use this and make what you need from it.



/** * Removes any characters which are not valid to be passed on the URL. */
static function string StripInvalidPasswordCharacters( string PasswordString, optional string InvalidChars=" \"/:?,=" )
{
   local int i;

      for ( i = 0; i < Len(InvalidChars); i++ )
      {
         PasswordString = Repl(PasswordString, Mid(InvalidChars, i, 1), "");
      }
      return PasswordString;
} 

Thanks. I’m doing something very similar to that to scrub illegal characters. But what I would like to do is make the text input box refuse to accept those characters at all.

let me look some more. If i remember right we had something like that for our players names.

What we did was add in a function and check the name thru it. Here is that function.




var array<string>BadWords;//you could make these in a config file and not in DefaultProperties

//See if any of our excluded words are in the string
function bool CensorName(string testName)
{
  local string stripedName;
  local int i;

 // add the words down in default properties section
   // strip any non-alphabetic characters from the name
    stripedName = "";
  for ( i = 0; i < Len(testName); i++ )
  {
   // Strip out any non alphabetic characters
   if ( (Mid(testName, i, 1) >= "a") && (Mid(testName, i, 1) <= "z") )
    {
      stripedName $= Mid(testName, i, 1);
    }
  }
  // Now see if any of the 'bad' words are in the name
  for ( i = 0; i < default.BadWords.Length; i++ )
    if ( -1 != InStr(stripedName, default.BadWords*) )
        return true;

   // Beep! censor it
   return false;
}


DefaultProperties
{
//Create our list of 'bad' words
  BadWords[0] = "****"
  BadWords[1] = "****"
  BadWords[2] = "****"
  BadWords[3] = "jew"
  BadWords[4] = "******"
  BadWords[5] = "bot"
BadWords[6] = "admin"
}


Not sure if you are wanting to do it this way or not, but if so use away.