Saturday, 30 January 2016

Prevent different key value on textbox keypress event .

http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000520.html


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style type="text/css">
        body
        {
            font-size: 9pt;
            font-family: Arial;
        }
    </style>
</head>
<body>
    Numeric Value: <input type="text" id="text1" class = "numeric" />
    <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>
</body>
</html>
http://www.aspsnippets.com/Articles/How-to-allow-only-numeric-values-numbers-in-a-TextBox-using-jQuery.aspx



No comments:

Post a Comment