I want to restrict a textbox value to a number with one decimal point, and one digit after decimal point.for eg:4.5,34.5,.4
Here is my code
function isNumberKey(obj,evt) {
var charCode = (evt.charCode) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46)
return false;
else {
var input = obj.value;
var len = obj.value.length;
var index = obj.value.indexOf('.');
if (index > 0 && charCode == 46) {
return false;
}
if (index >0 || index==0) {
var CharAfterdot = (len + 1) - index;
if (CharAfterdot > 2) {
return false;
}
}
if (charCode == 46 && input.split('.').length >1) {
return false;
}
}
//return true;
}
<ItemTemplate>
<asp:TextBox ID="txt1" runat="server" Width="50px" onkeypress="return isNumberKey(this,event);" maxlength="4" Style="text-align: right;"></asp:TextBox>
</ItemTemplate>
Using this in asp.net c#.this will be properly working in chrome and mozilla,but not working in IE