only number key in javascript
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
function IsNumber(evt,x)
{
var charCode = (evt.which) ? evt.which : event.keyCode ; //alert(charCode);
if(charCode != 46 && charCode != 45){ // . = 46 , - = 45
if ((charCode > 31 && (charCode < 48 || charCode > 57)) )
return false;
//alert($('#txtts').val());
var s= $(x).val().split('.') ; if(s[1].length > 1){ return false ;};
return true;
}else
if(charCode==45){ if($(x).val().length!=0) return false ; }
if(charCode==46){
if($(x).val().indexOf('.')!='-1'){ return false ;};
}
var s= $(x).val().split('.') ; if(s[1].length > 1){ return false ;};
return true;
}
</script>
<input type="text" name="t" id="t" onkeypress="return IsNumber(event , this);" /></td>
Comments
Post a Comment
If you Satisfied , Please Leave a comment