Advertisement
Guest User

Untitled

a guest
May 27th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. validate_input_number('.5int2dec');
  2. validate_input_number('.9int0dec');
  3.  
  4. function validate_input_number(selector){
  5. $(selector).on('focus',function(){
  6. $(this).attr("last_value", $(this).val());
  7. $(this).keyup( function (e) {
  8. var max_dec = selector.split("int")[1].split("dec")[0];
  9. var max_int = selector.split("int")[0].replace(".", "");
  10. var keys = [8, 9, 16, 17, 18, 19, 20, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 144, 145];
  11. var tecla = e.keyCode;
  12. if($.inArray(tecla, keys) == -1 && (tecla < 112 || tecla > 123)) {
  13. var splited = $(this).val().split(".");
  14. if (splited[0].length > max_int || (splited[1] != undefined && splited[1].length > max_dec) || ((tecla < 48 || tecla > 57) && (tecla < 96 || tecla > 105 ) && tecla != 110 && tecla != 190) || ($(this).val().split(".").length == 3 && (tecla == 110 || tecla == 190))){
  15. $(this).val($(this).attr("last_value"));
  16. e.preventDefault();
  17. e.stopPropagation();
  18. }else{
  19. $(this).attr("last_value", $(this).val());
  20. }
  21. }else{
  22. $(this).attr("last_value", $(this).val());
  23. }
  24. });
  25. });
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement