Posted By

mavrikicecool on 09/05/12


Tagged


Versions (?)

Javascript


 / Published in: JavaScript
 

restrict max length of a text box containing first position with a digit followed by a space

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>Untitled Document</title>
  6. <script type="text/javascript">
  7. function youcancall_dumbs()
  8. {
  9. var d = document.getElementById('dumb').value;
  10. if(!isNaN(d.charAt(0)) && d.charAt(0)!='')
  11. {
  12. document.getElementById('dumb').value= d.charAt(0)+' ';
  13. }
  14. else
  15. {
  16. alert('Please enter only digits at first place');
  17. document.f1.dumb.value="";
  18. document.getElementById('dumb').focus();
  19. }
  20. }
  21. </script>
  22. </head>
  23. <body>
  24. <form name="f1">
  25. <input type="text" name="dumb" id="dumb" maxlength="2" onkeyup="youcancall_dumbs()" />
  26. </form>
  27. </body>
  28. </html>

Report this snippet  

You need to login to post a comment.