4 Replies Latest reply on Mar 13, 2010 2:07 AM by kingsz1

    TextInput validation: keyboard typing or copy-paste?

    kingsz1

      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.

        • 1. Re: TextInput validation: keyboard typing or copy-paste?
          Arun Lal Level 2

          <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

          1 person found this helpful
          • 2. Re: TextInput validation: keyboard typing or copy-paste?
            kingsz1 Level 1

            Thank you. your advice is helpful.

            • 3. Re: TextInput validation: keyboard typing or copy-paste?
              GargMonika Level 1

              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.

              • 4. Re: TextInput validation: keyboard typing or copy-paste?
                kingsz1 Level 1

                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.