emprit

validasiangka

Aug 17th, 2013
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function numbersonly(myfield, e, dec)
  2. {
  3. var key;
  4. var keychar;
  5.  
  6. if (window.event)
  7. key = window.event.keyCode;
  8. else if (e)
  9. key = e.which;
  10. else
  11. return true;
  12. keychar = String.fromCharCode(key);
  13.  
  14. // control keys
  15. if ((key==null) || (key==0) || (key==8) ||
  16. (key==9) || (key==13) || (key==27) )
  17. return true;
  18.  
  19. // numbers
  20. else if ((("0123456789").indexOf(keychar) > -1))
  21. return true;
  22.  
  23. // decimal point jump
  24. else if (dec && (keychar == "."))
  25. {
  26. myfield.form.elements[dec].focus();
  27. return false;
  28. }
  29. else
  30. return false;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment