I have a function that allow input field to receive numbers and the decimal point. How can I allow the backspace key as well ?
function verifierCaracteres(event) {
var keyCode = event.which ? event.which : event.keyCode;
var touche = String.fromCharCode(keyCode);
var champ = document.getElementById('mon_input');
var caracteres = '.0123456789';
if(caracteres.indexOf(touche) >= 0) {
champ.value += touche;
}
}
And my HTML:
<input type="text" name="Patient_Amount" id="mon_input" onkeypress="verifierCaracteres(event); return false;"/>