bandi-c
5/16/2014 - 11:12 AM

Limit text input to a decimal number with max 2 decimals. Need to place in onkeypress "return validateDecimal(event)"

Limit text input to a decimal number with max 2 decimals. Need to place in onkeypress "return validateDecimal(event)"

function validateDecimal( evt )
{
	var value = $('#input_comision').val();
	
	evt = (evt) ? evt : window.event;
	var charCode = (evt.which) ? evt.which : evt.keyCode;
	
	return ( value.length == 0 || charCode < 31 || ( ( charCode >= 48 && charCode <= 57 || charCode == 46 ) && /^\d+\.?(\d{1})?$/.test(value) ) ) ? true : false;
}