accept only numeric data from keyboard in javascript


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



Copy this code and paste it in your HTML
  1. <HTML>
  2. <HEAD>
  3. <SCRIPT language=Javascript>
  4. <!--
  5. function isNumberKey(evt)
  6. {
  7. var charCode = (evt.which) ? evt.which : event.keyCode
  8. if (charCode > 31 && (charCode < 48 || charCode > 57))
  9. return false;
  10.  
  11. return true;
  12. }
  13. //-->
  14. </SCRIPT>
  15. </HEAD>
  16. <BODY>
  17. <INPUT id="txtChar" onkeypress="return isNumberKey(event)" type="text" name="txtChar">
  18. </BODY>
  19. </HTML>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.