Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/06/2009, 04:41
Avatar de chiquirf
chiquirf
 
Fecha de Ingreso: noviembre-2005
Ubicación: Madrid
Mensajes: 215
Antigüedad: 18 años, 6 meses
Puntos: 3
solo números, comas y puntos

Hola a todos,

Necesito una función que me permita escribir en un input text solo números, coma, punto, Tabulador y Backspace.

He buscado en las Faq's y en Internet y he encontrado esto ( he juntado todo lo que encontré):

Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<
title>solo numeros</title>

<
script type="text/javascript" language="javascript">
<!--
// FUNCION PARA SOLO DEJAR ESCRIBIR NUMEROS CON DECIMALES
var nav4a window.Event true false;
function 
acceptNumDecim(evt){    
// NOTE: Backspace=8, tab=9, Enter=13, '0'=48, '9'=57, comma=188, decimal point=110
var key nav4a evt.which evt.keyCode;    
return (
key == || key == || key == 13 || (key >= 48 && key <= 57) || key == 188 || key == 110);
}

// FUNCION PARA SOLO DEJAR ESCRIBIR NUMEROS ENTEROS
var nav4b window.Event true false;
function 
acceptNumEnt(evt){    
// NOTE: Backspace=8, tab=9, Enter=13, '0'=48, '9'=57, comma=188, decimal point=110
var key nav4b evt.which evt.keyCode;    
return (
key == || key == || key == 13 || (key >= 48 && key <= 57) );
}

function 
LP_data(){ 
    var 
key=window.event.keyCode;//codigo de tecla. 
    
if ( !(key == || key == || key == 13 || (key >= 48 && key <= 57) || key == 188 || key == 110) ){//si no es numero  
        
window.event.keyCode=0;//anula la entrada de texto. 
    
}

-->
</script>
</head>
<body>
<form action="solonum.html" method="post" name="Form1">
<br /><br />
acceptNumDecim <input type="text"  onKeyPress="return acceptNumDecim(event)"  value=""  />
<br /><br />
acceptNumEnt <input type="text"  onKeyPress="return acceptNumEnt(event)"  value=""  />
<br /><br />
LP_data <input type="text" onKeypress="LP_data()"  value=""  />
<br /><br />
<input name="Recargar" type="submit" value="Regargar" />
</form>
</body>
</html> 

El problema es que no hace exactamente "lo que le indico", y en IE y FF actúan distinto:

Internet Explorer (6, 7 y 8):
OK: números, backspace, del/sup y tabulador
KO: letras, coma, punto, y otros caracteres


Firefox 3:
OK: números, backspace
KO: del/sup, tabulador, letras, coma, punto, y otros caracteres

Y para colmo de males, las 2 primeras funciones no me dejan escribir nada desde un portatil... NO ME PREGUNTEN PORQUE, pero así es, no me deja escribir ni los números, este portátil tiene el Windows Vista, y tenía el IE7 y ahora tiene el IE8 y da igual.

Alguien me puede ayudar para hacerlo funcionar ????

Muchas gracias

Saludos

Carlos
__________________
=================
Chiqui nunca muere ! ! !

Última edición por chiquirf; 11/06/2009 a las 07:38