How do I disable right click on my web page?


Using javascript

     use oncontextmenu="return false;" on your HTML body tag.      

Using jQuery

    
$(function() {
        $(this).bind("contextmenu", function(e) {
            e.preventDefault();
        });
    });
Advertisements

Alphanumeric & Number Validation using Onkeypress event


<script language="javascript" type="text/javascript">
function isNumberKey(evt){ // Numbers only
    var charCode = (evt.which) ? evt.which : event.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}
     function isAlphaNumeric(e){ // Alphanumeric only
            var k;
            document.all ? k=e.keycode : k=e.which;
            return((k>47 && k<58)||(k>64 && k<91)||(k>96 && k<123)||k==0);
         }
    </script>
----------------------------------------------------------------
OnKeypress="javascript:return isNumberKey(event);"
---------------------------------------------------------------
OnKeypress="javascript:return isAlphaNumeric(event,this.value);"

How to restrict digit & decimal


<script language="javascript" type="text/javascript">
function isNumberKey(evt){
var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode &gt; 31 &amp;&amp; (charCode &lt; 48 || charCode &gt; 57))
return false;
return true;
}

function isNumberKeyWithDecimal(evt){
var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode != 46 &amp;&amp; charCode &gt; 31 &amp;&amp; (charCode &lt; 48 || charCode &gt; 57))
return false;
return true;
}
</script>
onkeypress="return isNumberKey(event)"
onkeypress="return isNumberKeyWithDecimal(event)"