// 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