Posted By

xmaestro on 12/01/11


Tagged

as type you validationvalidate


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

slashyy77
artistandalias


Javascript : Validate As You Type


 / Published in: JavaScript
 

Javascript : Validate As You Type

  1. //Javascript//
  2.  
  3. function validateAsYouType(inputElementId)
  4. {
  5. var val=inputElementId.value;
  6. var lastLetter=val.substring((val.length-1),val.length);
  7.  
  8. if(isNaN(lastLetter))
  9. {
  10. //Input is OK. Let things be as they are.
  11. }
  12.  
  13. else
  14. {
  15. //Input is not OK. Rmove the last entered character
  16.  
  17. var new_val=val.substr(0,val.length-1);
  18. document.getElementById('inputtype').value=new_val;
  19.  
  20. }
  21.  
  22. }
  23.  
  24. //Javascript//
  25.  
  26.  
  27. Sample usage:
  28.  
  29. <input type="text" value="" id="inputtype" onkeyup="return validateAsYouType(this);" />

Report this snippet  

You need to login to post a comment.