Javascript Chapter:3



Javascript which checks whether there is any alphabet in the variable that is given on keydownEvent.

 <script type="text/javascript">

        function isNumeric(event) {
            //            alert(event.shiftKey);
            keyCode = event.keyCode;
            document.getElementById('lbl').value = keyCode;

            isShift = event.shiftKey;
            {
   if ([keyCode == 52 || keyCode == 53  || keyCode == 8  ) && isShift == true) {
                return true;

            }
            else if (((keyCode >= 48 && keyCode <= 57) || (keyCode >= 96 && keyCode <= 105) || keyCode == 8  ) && isShift == false) {
                return true;
            }
            else {
                return false;
            }
        }
 
    </script>

 <asp:TextBox ID="TextBox1" runat="server" onkeydown="return isNumeric(event)">
        </asp:TextBox>



Javascript which checks whether there is any alphabet in the variable that is given on KeyPress Event.



 function runScript(e) {
            var alphaExp = /.*[a-zA-Z].*/;
            var txtValue= document.getElementById("txtValidation").value;
            var BoolValue= false;
            BoolValue= alphaExp .test(txtValue);

            if (BoolValue== true) {
                alert("AlphaExpressions not allowed");
            }
           
        }

Javascript which checks whether there is any numerals and Special Characters

 var numericExpression = /^[0-9]+$/;
            var SpecialExp= /[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\~\=\|]/;
 if (txtValue.match(numericExpression) || txtValue.match(SpecialExp) ) 
           {
               alert("You 've Entered Numerals and Symbols");
               }

If we want to block any label from displaying its Text

 protected void Page_Load(object sender, EventArgs e)
        {
           
                imgSubmit.OnClientClick = "document.getElementById('" + lblMessage.ClientID + "').style.display='none';";

HappyCoding ! 😉

Advertisements

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: