Monday, 29 July 2013

Restriction enter only numeric value in textbox using jquery


<td class="style3">
                    <asp:TextBox ID="TextBox6" runat="server" class="numeric"></asp:TextBox>
                    <span class="error" style="color: Red; display: none">* Input digits (0 - 9)</span>
                    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

    <script type="text/javascript">

        var specialKeys = new Array();

        specialKeys.push(8); //Backspace

        $(function () {

            $(".numeric").bind("keypress", function (e) {

                var keyCode = e.which ? e.which : e.keyCode

                var ret = ((keyCode >= 48 && keyCode <= 57) || specialKeys.indexOf(keyCode) != -1);

                $(".error").css("display", ret ? "none" : "inline");

                return ret;

            });

            $(".numeric").bind("paste", function (e) {

                return false;

            });

            $(".numeric").bind("drop", function (e) {

                return false;

            });

        });

    </script>

                </td>

No comments:

Post a Comment