Monday, April 8, 2013

Disable right click control and many keys

function DisableRightClick(event)
       {
               if (event.button==2)
               {
               alert("Right Clicking not allowed!");
               }
       }


 function DisableCtrlKey(e)
           {
               var code = (document.all) ? event.keyCode:e.which;
               var message = "Ctrl key functionality is disabled!";
               if (parseInt(code)==17)
                       {
                       alert(message);
                       window.event.returnValue = false;
                       }
               if (parseInt(code)==18)
                       {
                       alert("Alt key functionality is disabled!");
                       window.event.returnValue = false;
                       }
               if (parseInt(code)==32)
                       {
                       alert("Space key is disabled");
                       window.event.returnValue = false;
                       }
               if (parseInt(code)==45)
                       {
                       alert("Insert key is disabled!");
                       window.event.returnValue = false;
                       }
           }

oncopy="return false;" onpaste="return false;" oncut="return false;" ondragstart="return false" onselectstart="return false"

Wednesday, April 3, 2013

trim in javascript

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function isBlank(s)
{
     if(s==null)
     return true;
     if(s.match(/^\s*$/))
     {
         return true
     }
     return false;
}

    if(isBlank(trim(objTourName.value,' ')) || trim(objTourName.value,' ').length ==0)
    {
        alert("Tour Name can not be left blank.");
        objTourName.focus();
        return false;
    }

Only numbers decimal not allowed

<script type="text/javascript">
        function checkIt(evt) {
            evt = (evt) ? evt : window.event
            var charCode = (evt.which) ? evt.which : evt.keyCode
            if (charCode > 31 && (charCode < 48 || charCode > 57)) {
                alert("Only Numbers allowed");
                return false
            }
            
            document.getElementById("errorMessage").innerHTML = ""
            return true
        }
        function Changed( textControl )
        {
           if(textControl.value.indexOf(".") !== -1)
           {
               alert("decimal values not allowed");textControl.value='';return false;
           }
           return true;
        }

</script>
<asp:TextBox ID="TextBox1" runat="server" onKeyPress="return checkIt(event)" onchange="javascript: Changed(this);" ></asp:TextBox>