반응형
input type number max length
<input name="myinput_drs"
oninput="maxLengthCheck(this)"
type = "number"
maxlength = "3"
min = "1"
max = "999" />
<script>
// This is an old version, for a more recent version look at
// https://jsfiddle.net/DRSDavidSoft/zb4ft1qq/2/
function maxLengthCheck(object)
{
if (object.value.length > object.maxLength)
object.value = object.value.slice(0, object.maxLength)
}
</script>
<input name="somename"
oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
type = "number"
maxlength = "6"
/>
$("input[name='minutes']").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;
}
}
});
반응형
'프로그래밍 > Web' 카테고리의 다른 글
[javascript] youtube 영상을 모바일에서 iFrame으로 Autoplay=1 (0) | 2017.02.17 |
---|---|
깃허브에서 인기 높은 구글의 오픈소스 프로젝트 10종 (0) | 2017.02.16 |
console.log를 지워야하는 이유 (0) | 2017.01.12 |
visual studio code - 설치하기 https://code.visualstudio.com/ (0) | 2016.12.19 |
[javaScript] TypeScript (0) | 2016.12.01 |