Javascript,jQuery
INPUT 박스에서 숫자만 입력 되도록 설정
올라치노
2016. 10. 31. 20:14
스크립트 단
// 숫자만 입력.
function isNumberKey(evt){
var theEvent = evt || window.event;
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode( key );
var regex = /[0-9]|\./;
if( !regex.test(key) ) {
theEvent.returnValue = false;
if(theEvent.preventDefault) theEvent.preventDefault();
}else{
theEvent.returnValue = true;
}
}
HTML
<input type="text" name="이름" onkeypress="return isNumberKey(event)" style="ime-mode:disabled;" />