Skip navigation
Home/Support/

Forums

65 Views 4 Replies Latest reply: Mar 13, 2010 3:07 AM by kingsz1 RSS
kingsz1 User 9 posts since
Dec 2, 2009
Currently Being Moderated

Mar 9, 2010 2:33 PM

TextInput validation: keyboard typing or copy-paste?

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.

  • Arun Lal User 27 posts since
    Dec 17, 2007

    <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

  • GargMonika User 43 posts since
    Feb 25, 2010

    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.

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

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