restrict non-numeric entries


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function numeralsOnly(evt) {
  2. evt = (evt) ? evt : event;
  3. var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
  4. if (charCode > 31 && (charCode < 48 || charCode > 57)) {
  5. return false;
  6. }
  7. return true;
  8. }
  9.  
  10. yourFiled.onkeypress = numeralsOnly(e);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.