Monday, December 15, 2008

How to avoid Copy Paste in input fields

Here is a code to avaoid 'Ctrl+V' use by the users on field that you want to enforce double validation on:

function KeyPressed(e) 
  { 
    var evt = typeof window.event != 'undefined' ? window.event : e; 
    var val = evt.keyCode == 86; 
    if (evt.ctrlKey && val) 
    { alert(evt.ctrlKey +", "+ val);
      if (evt.stopPropagation) 
      { 
        evt.preventDefault(); 
        evt.stopPropagation(); 
      }
      else 
      { 
        evt.cancleBubble = true; 
        evt.returnValue = false; 
      } 
  } 
crmForm.all.firstname.attachEvent("onkeydown",KeyPressed);

No comments: