Mar 9, 2010 2:33 PM
TextInput validation: keyboard typing or copy-paste?
-
Like (0)
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.
<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
Thank you. your advice is helpful.
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.
hi, you can get more detail of keyboard control from "Programming ActionScript 3.0", the docment from Adobe
http://livedocs.adobe.com/flex/3/html/help.html?content=Part6_ProgAS_1 .html
look at chapter 22 - "Capturing user input" there are some codes to check user key typing.
I am not able to prevent copy-paste, but from keycode, we know copy-paste use CTRL and v key.
Copyright © 2011 Adobe Systems Incorporated. All rights reserved.
Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy (updated 07-14-2009).