Originariamente inviato da milazzo
Un'informazione

... ho questo scriptino che consente di controllare che in un campo vengano immessi solo valori numerici come posso far inserire tra i caratteri concessi anche questi:
- , e . in modo che possano essere inseriti anche numeri negativi o decimali (4,5 o 4.500 o - 3.200 per esempio)
<script type="text/javascript">
function verificavalore(test)
{
str = new String(test.value);
con = 0;
for(k = 0; k < str.length; k++)
{
c = str.charAt(k);
if (!(c >= '0' && c <= '9'))
{
con++;
}
}
if(con > 0)
{
alert("Campo \"DISPONIBILITA\" Contiene caratteri non validi. Per cortesia inserisci numeri e non lettere.");
test.value = "";
}
}
</script>
Un grazie per l'aiutone.
Questo dovrebbe fa quello che chiedi:
codice:
<!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>Documento senza titolo</title>
<script language="javascript">
function VerificaInput(dato){
if(!dato.value.match(/^[0-9 ,\. \- e]+$/)){
alert("Ci sono carattere non amessi");
dato.value='';
return false;
}
}
</script>
</head>
<body>
<form name="form1" id="form1" method="get" action="">
<input name="tuocampo" id="tuocampo" type="text" onBlur="VerificaInput(this)" />
</form>
</body>
</html>