Friday, 13 November 2015

JavaScript : Restrict multiple time entry of and char or number or decimal using javascript on keydown


// HTML

<input type="text" class="decimal" value="" />
            
 or

<asp:TextBox ID="txt_actID" runat="server">

///////  JS

$('input').on('keydown', function (event) {
                return isNumber(event, this);
            });

            function isNumber(evt, element) {
                var charCode = (evt.which) ? evt.which : evt.keyCode;
                if ((charCode != 190 || $(element).val().indexOf('.') != -1) && (charCode != 110 || $(element).val().indexOf('.') != -1)
                && ((charCode < 48 && charCode != 8) || (charCode > 57 && charCode < 96) || charCode > 105))
                    return false;
                return true;
            }


/////////////////or

<asp:TextBox ID="TextBox1" runat="server"   onkeydown="return isNumber(event, this);">

/// js

 function isNumber(evt, element) {
                var charCode = (evt.which) ? evt.which : evt.keyCode;
                if ((charCode != 190 || $(element).val().indexOf('.') != -1) && (charCode != 110 || $(element).val().indexOf('.') != -1)
                && ((charCode < 48 && charCode != 8) || (charCode > 57 && charCode < 96) || charCode > 105))
                    return false;
                return true;
            }


No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...