A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Textfield - Bad Language Restrictor

  1. #1
    MindGem Graphics Inc. JediMind's Avatar
    Join Date
    Nov 2001
    Location
    Stockholm/Sweden
    Posts
    407

    Textfield - Bad Language Restrictor

    Hey, can I restrict a sertain string within a textfield?

    if(textfield.text == *"****"*)
    {
    }

    type of thing?....

  2. #2
    Senior Member
    Join Date
    Jan 2009
    Posts
    208
    I think you need to create an array (or vector) or forbidden strings and then loop to see it any is contained.

  3. #3
    Senior Member
    Join Date
    Jul 2008
    Posts
    391
    What's the textfield for? What kind of restriction do you want? I have 2 different kinds in mind:
    -Like a chatbox kind of thing, you can see yourself type the word but it gets censored when you press enter or something.

    -The instant you type the word in the textfield the word changes into stars immediately or gets cut out. Like if you press the k key to finish that 4 letter word, those 4 letters turn into stars or disappear from the textfield completely.

  4. #4
    MindGem Graphics Inc. JediMind's Avatar
    Join Date
    Nov 2001
    Location
    Stockholm/Sweden
    Posts
    407
    I want to check if the textfield contains swear words and then let the user know that it's not allowed.

    I know about the stars, that's for passwords and you set that up in the panel. It's not going to work in this case because it's the users choosen name in the textfield.

  5. #5
    MindGem Graphics Inc. JediMind's Avatar
    Join Date
    Nov 2001
    Location
    Stockholm/Sweden
    Posts
    407
    if(textfield.text == *"swearword"*)
    {
    trace("you can't use swear words.");
    }

    That's about the thing I want...


    regbolD.
    But how does that work,
    if you have an array it just checks if it matches the container like this

    var test:Array = new Array("blah","bleh");
    if(textfield.text == new[0])
    {
    trace("you can't use 'blah' in your name");
    }

    Or is it possible to check if the string contains the word like this:
    if(textfield.text == *test[0]*) see what I'm aiming for?

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You can use indexOf to determine if a substring occurs anywhere. Or you can use a regular expression to do more flexible matching. indexOf sounds like it's suitable for you.

  7. #7
    MindGem Graphics Inc. JediMind's Avatar
    Join Date
    Nov 2001
    Location
    Stockholm/Sweden
    Posts
    407
    Yea, I guess I have to loop using indexOf and a bit complicated checking words using it too thinking about it.

    Thanx for the reply.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center