Si un carácter es alfanumérico o no


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



Copy this code and paste it in your HTML
  1. function alphanumeric(val){
  2. var regex=/^[0-9A-Za-z]+$/;
  3. if(regex.test(val)){
  4. return true;
  5. }
  6. else {
  7. return false;
  8. }
  9. }
  10.  
  11. function blah(e){
  12. var keynum = null;
  13. if(window.event) // IE
  14. {
  15. keynum = e.keyCode;
  16. }
  17. else if(e.which) // Netscape/Firefox/Opera
  18. {
  19. keynum = e.which;
  20. }
  21.  
  22. if ( (keynum!=null)&& (alphanumeric(keynum) )
  23. {
  24. // Se ha pulsado un alfanumérico
  25. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.