javascript - Input Validation - How to allow backspace to work in my method -


i have function allow input field receive numbers , decimal point. how can allow backspace key ?

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 html:

<input type="text" name="patient_amount" id="mon_input" onkeypress="verifiercaracteres(event); return false;"/> 

use keycode == 8 in validation. 8 keycode backspace.

really, job regex , replace. how typically go process. here example.

function verifiercaracteres() {     var inputele = document.getelementbyid("mon_input");     var value = inputele.value;     inputele.value = value.replace(/([^0-9\.])+/g,''); } 

this remove characters input not 0-9 or .


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -