/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function numeralsOnly(evt) { evt = (evt) ? evt : event; var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0)); if (charCode > 31 && (charCode < 48 || charCode > 57)) { return false; } return true; } yourFiled.onkeypress = numeralsOnly(e);