Numbers only in an input field


/ Published in: jQuery

Méthode n'autorisant que les nombres (positifs/négatifs/décimaux avec virgules ou points) dans un champ


Copy this code and paste it in your HTML
  1. $("#inputTarif").keypress(function(event){
  2. var charCode = (event.which) ? event.which : window.event.keyCode;
  3. if (charCode <= 13) { return true;}
  4. else {
  5. var keyChar = String.fromCharCode(charCode);
  6. var Exp = new RegExp("[0-9,.-]");
  7. return Exp.test(keyChar);
  8. }
  9. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.