Click here to Skip to main content
15,900,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Team,

I have the code as follow in javascript on KeyDown Event.

C#
function keyPressFunctionForValidations(e) {
              debugger;
              var charCode = (e.which) ? e.which : e.keyCode
              switch (e.type) {
                  case 'keydown':
                      if (e.ctrlKey == true && (charCode == 118 || charCode == 86)) {
                          e.preventDefault();
                          return;
                      }

                      var isValid = (charCode >= 37 && charCode <= 40) || (charCode >= 65 && charCode <= 90) || charCode == 32 || charCode == 46 || charCode == 8 || charCode == 9 || charCode == 67 || charCode == 86 || charCode == 17;
                      if (isValid == false) {
                          e.preventDefault();
                          return;
                      }
                      break;
                  case 'paste':
                      e.preventDefault();
                      return;
                      break;
              }

          }


i have the paste function as follow
 function validateOnPaste(e) {
                debugger;
                var theEvent = e || window.event;
                var key = theEvent.keyCode || theEvent.which;
                key = String.fromCharCode(key);
                var regex = /[a-zA-z]|\s/;
                if (!regex.test(key)) {
                    e.preventDefault();
                    return;
                }
            }


Now i want to perform one task on textbox that is
i want to copy and paste the values in textbox through keydown event using javascript keycode.

How should i get it?
Thanks
HArshal Raut
Posted
Updated 29-Jan-14 23:27pm
v2
Comments
[no name] 30-Jan-14 4:30am    
i have the paste function as follow
function validateOnPaste(e) {
debugger;
var theEvent = e || window.event;
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode(key);
var regex = /[a-zA-z]|\s/;
if (!regex.test(key)) {
e.preventDefault();
return;
}
}
Karthik_Mahalingam 30-Jan-14 10:28am    
what is the task?
what is the issue ?

1 solution

You can easily detect Copy, Paste and Cut using jQuery.

Refer - How To Detect Copy, Paste And Cut Behavior With JQuery[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900