Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

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

    I'm trying to use https://help.adobe.com/en_US/FlashPl...TextField.html to block input of illegal characters, but I can't get it to work. I'm trying both of these:

    Code:
    textInput.restrict = "^\"";
    and also

    Code:
    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.
    Check out Himeko Sutori, the upcoming tactical RPG where you control armies of over 100 unique characters.

    #2
    use this and make what you need from it.
    Code:
    /** * 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;
    }
    Last edited by gamepainters; 02-06-2021, 03:19 PM.

    Comment


      #3
      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.
      Check out Himeko Sutori, the upcoming tactical RPG where you control armies of over 100 unique characters.

      Comment


        #4
        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.
        Code:
        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[i]) )
                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.
        Last edited by gamepainters; 02-07-2021, 06:03 PM.

        Comment

        Working...
        X