Ver Mensaje Individual
  #2 (permalink)  
Antiguo 28/08/2009, 14:43
Avatar de uselox
uselox
 
Fecha de Ingreso: agosto-2008
Ubicación: Lima, Perú
Mensajes: 168
Antigüedad: 15 años, 8 meses
Puntos: 12
Respuesta: Validacion onkeypress

prueva con algo asi:
Código HTML:
<script language="javascript">
function validarNum(event, element, _float){
	event = event || window.event;
	var charCode = event.which || event.keyCode;
	if (charCode == 8 || charCode == 13 || (_float ? (element.value.indexOf('.') == -1 ? charCode == 46 : false) : false))
		return true;
	else if ((charCode < 48) || (charCode > 57))
		return false;
	return true;
}
</script> 
...

Código HTML:
<!-- no decimales -->
<input type="text" onkeypress="validarNum(event, this)"/>

<!-- con decimales -->
<input type="text" onkeypress="validarNum(event, this, true)"/>