Posted By

laxman2021 on 12/05/12


Tagged

validation numeric spaces textBox


Versions (?)

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


 / Published in: PHP
 

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

Validates Numericals in a text box.

Validates spaces in a text box.

  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>

Report this snippet  

You need to login to post a comment.