Java script for Disable the cut, copy, paste and accepts the number and alphabets only


1) Java script for disable the cut, copy, paste task from the textbox

               a). By Disabling the mouse right click

function no_Cpy_Mouse(event) {
 var isRight = (event.button) ? (event.button == 2) : (event.which == 3);
    if (isRight) {
        alert('Right Click is disable.');
        return false;
    }
    return true;
}

                b). By Disabling the key control

function no_Cpy_byKey(event) {
    var forbiddenKeys = new Array('c', 'x', 'v');
    var keyCode = (event.keyCode) ? event.keyCode : event.which;
    var isCtrl;

    if (window.event)
        isCtrl = event.ctrlKey
    else
        isCtrl = (window.Event) ? ((event.modifiers & Event.CTRL_MASK) == Event.CTRL_MASK) : false;

    if (isCtrl) {
        for (i = 0; i < forbiddenKeys.length; i++) {
            if (forbiddenKeys[i] == String.fromCharCode(keyCode).toLowerCase()) {
                alert('Please type this for a reason!');
                return false;
            }
        }
    }
    return true;
 }

2. java script for accepts only numbers

function number_only(event, dec) {
     var key;
     var keychar;
     if (window.event) {
         key = window.event.keyCode;
 
     }
     else if (event) {
         key = event.which;
        

     }
     else {
        
         return true;
     }
     keychar = String.fromCharCode(key);
     if ((key == null) || (key == 0) || (key == 8 ) || (key == 9) || (key == 13) || (key == 27)) {
                  return true;
     }
              else if ((("0123456789").indexOf(keychar) > -1)) {

         return true;
     }
     else if (dec && (keychar == ".")) {
         return true;
     }
     else 
         return false;
 
 }

3. java script for accepts only alphabets

function alphabet_only() {

         var keyStroke = (event.which) ? event.which : (window.event) ? window.event.keyCode : -1;
         var returnValue = false;

         if (((keyStroke >= 65) && (keyStroke <= 90)) || ((keyStroke >= 97) && (keyStroke <= 122)))
             returnValue = true;

         if (window.event)
             window.event.returnValue = returnValue;

         return returnValue;
 }

Advertisements

2 thoughts on “Java script for Disable the cut, copy, paste and accepts the number and alphabets only

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s