Skip navigation
kingsz1
Currently Being Moderated

TextInput validation: keyboard typing or copy-paste?

Mar 9, 2010 2:33 PM

Hi all. In my application, I want to check the username and password input. I hope the app only accept the human keyboard typing input for the username and password, and refuse the copy-paste input.

 

What is the approach for this? Any suggestion is appreciated. Thank you.

  • Currently Being Moderated
    Community Member
    Mar 9, 2010 10:25 PM

    <mx:TextInput id="txtIp" change="txtChangeHandler(event)"/>
       
        <mx:Script>
            <![CDATA[
                private var controlFlag:Boolean = false;
                private function init():void{
                    this.addEventListener(KeyboardEvent.KEY_DOWN,kbdHandler);
                    this.addEventListener(KeyboardEvent.KEY_UP,kbuHandler);
                }
                private function kbdHandler(event:KeyboardEvent):void{
                    if(event.keyCode==Keyboard.CONTROL){
                        controlFlag = true;
                    }
                    if(controlFlag && event.keyCode==Keyboard.V){
                        event.preventDefault();
                    }
                }
                private function kbuHandler(event:KeyboardEvent):void{
                    if(event.keyCode==Keyboard.CONTROL){
                        controlFlag = false;
                    }
                }
                private function txtChangeHandler(event:Event):void{
                    //
                }
            ]]>
        </mx:Script>

     

     

    Try with this logic.. Let me know if it helps

    |
    Mark as:
  • Currently Being Moderated
    Mar 12, 2010 5:58 AM

    I am not able to get this functionality by using your code.

     

    Keyboard.V is not available.

    Can you please tell me the solution.

    I tried with the Key code value for V is 72 but still it doent prevent me for copy-paste.

    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points