emprit

validasinomeronly

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