Skip to content

Instantly share code, notes, and snippets.

@zhukovsergei
Created December 28, 2015 10:06
Show Gist options
  • Save zhukovsergei/0ff786b61c52df6347dc to your computer and use it in GitHub Desktop.
Save zhukovsergei/0ff786b61c52df6347dc to your computer and use it in GitHub Desktop.
Ограничение на ввод символов в текстовом поле
$("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