Salve a tutti, sono nuovo del forum ed è da relativamente poco che programmo in JavaScript.
Volevo permettere l'inserimento di valori numerici e valori in virgola mobile in un form, utilizzando JavaScript. Ho provato ad utilizzare questa funzione, ma non so come settare il valore della variabile regex in modo che possano essere inseriti anche i punti. Grazie anticipatamente per la vostra risposta.
codice:
function onlyNumeric(evt)
{
var theEvent = evt || window.event;
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode(key);
var regex = /[0-9]/;
if (!regex.test(key)) {
theEvent.returnValue = false;
if (theEvent.preventDefault) theEvent.preventDefault();
}
}