A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] Limiting input text to unique characters

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    16

    resolved [RESOLVED] Limiting input text to unique characters

    I already know how to limit my input text to a number of characters, but how would I go about (if possible) making sure characters do not repeat? In other words, I have a ten character input text box and I want you to be able to type pretty much any character but only one of each.

    Example:

    AFKEIOPCNK

    What I'm trying to eliminate is this:

    AANHDKDDJI

    If that isn't possible, I'd like to instead detect if there are repeated characters so I can just say "that's invalid".
    Last edited by Rajada; 04-20-2011 at 01:30 AM.

  2. #2
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Well unfortunately, you would have to do one of two things (at least of what I can think of). Either you would have a variable, that would track the use of a character. If a character is used, then an associated variable would be set to true. The next time they press the character, if when checking that variable and true is returned, then the keyboard entry is ignored as a duplicate.

    The other way would be to compare the keyboard entry (each and every entry) against the text in the input field. If a character in the field matches the keyboard entry, then it is ignored (user notified) otherwise it is inserted at the end of the text group.

    Of course, there are much smarter people out there and they may have better options, these are just what jumped in my head at the moment.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  3. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    16
    I probably don't want to have to create a variable for every character, whether or not it is just 26 of them for just the uppercase alphabet I'm using. It seems like it would be a ton of code to reset those variables.

    Since its limited to ten characters, and I have an 'Apply' button basically, couldn't I just compare each character to every other character and if at least one matches another just return a message stating the entry is invalid? Oh, I just realized I need to enforce a minimum character count of ten for this to work too. So maybe I need to see if AS3 has any functions like PHP does that allow you to take apart strings and determine string length and such.

    EDIT:

    Haha! Nevermind then! All my OOP experience came in handy and I just used this which works like a charm...

    Code:
    function Decrypt(Event:MouseEvent):void
    {
    	var KeyString:String = InputBox.text.toString();
    	var com1:Number = 0;
    	var com2:Number = 0;
    	
    	if(KeyString.length < 10)
    	{
    		ResponseBox.text = "INVALID KEY! ERROR NO. 001";
    		return;
    	}
    	else 
    	
    	myLoop: for(com2 = 0; com2 <= 10; com2++)
    	{	
    		if((KeyString.charAt(com1)) == (KeyString.charAt(com2)) && ((com1 < 10) && (com2 < 10) && (com1 != com2)))
    		{
    			ResponseBox.text = "INVALID KEY! ERROR NO. 002";
    			 break myLoop;
    		}
    		else
    			{
    			if(com2 == 10)
    			{
    				com2 = 0;
    				com1++;
    			}
    			if(com1 == 10)
    			{
    				BeginDecryption();
    				break myLoop;
    				
    			}
    		}
    	}
    	
    }
    Last edited by Rajada; 04-20-2011 at 04:00 PM.

Tags for this Thread

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