coding/short code

javascript 숫자만 입력 가능

100a 2019. 6. 4. 15:38
/* javascript */

function inputOnlyNum(event){
  var acode = event.keyCode;
  if(acode == 37 || acode == 39 || acode == 8 || acode == 127 || acode == 9 || (acode>47 && acode<58) || (acode>95 && acode<106)) {
      //
  }else{
      return false; //숫자가 아닐때 작성이 안됨
  }
}


/* html */

<input type="text" name="number"  onkeydown="javascript:return inputOnlyNum(event);">