Created
December 28, 2015 10:06
-
-
Save zhukovsergei/0ff786b61c52df6347dc to your computer and use it in GitHub Desktop.
Ограничение на ввод символов в текстовом поле
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("input[type='number']").on('keyup keypress blur change', function(e) { | |
//return false if not 0-9 | |
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) { | |
return false; | |
}else{ | |
//limit length but allow backspace so that you can still delete the numbers. | |
if( $(this).val().length >= parseInt($(this).attr('maxlength')) && (e.which != 8 && e.which != 0)){ | |
return false; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment