Onkeypress event Javascript spacekey event Validation for (Integers, Spaces) Textbox.


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

Validates Numericals in a text box.

Validates spaces in a text box.


Copy this code and paste it in your HTML
  1. <script language=Javascript>
  2.  
  3. function isSpaceKey(evt)
  4. {
  5. var charCode = (evt.which) ? evt.which : event.keyCode
  6. if ((charCode == 32))
  7. {
  8. alert("Spaces are not allowed");
  9. return true;
  10. }
  11. else ((charCode >= 47 && charCode <= 58))
  12. {
  13. alert("Numerics are not allowed");
  14. return true;
  15. }
  16. return true;
  17. }
  18.  
  19. </script>
  20.  
  21. <script language=Javascript>
  22.  
  23. function isAlphaKey(evt)
  24. {
  25. var charCode = (evt.which) ? evt.which : event.keyCode
  26. if ((charCode >= 47 && charCode <= 58))
  27. {
  28. alert("Enter Numeric Values");
  29. return true;
  30. }
  31. return true;
  32. }
  33.  
  34. </script>

URL: http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.