Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- validate_input_number('.5int2dec');
- validate_input_number('.9int0dec');
- function validate_input_number(selector){
- $(selector).on('focus',function(){
- $(this).attr("last_value", $(this).val());
- $(this).keyup( function (e) {
- var max_dec = selector.split("int")[1].split("dec")[0];
- var max_int = selector.split("int")[0].replace(".", "");
- var keys = [8, 9, 16, 17, 18, 19, 20, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 144, 145];
- var tecla = e.keyCode;
- if($.inArray(tecla, keys) == -1 && (tecla < 112 || tecla > 123)) {
- var splited = $(this).val().split(".");
- 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))){
- $(this).val($(this).attr("last_value"));
- e.preventDefault();
- e.stopPropagation();
- }else{
- $(this).attr("last_value", $(this).val());
- }
- }else{
- $(this).attr("last_value", $(this).val());
- }
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement