Check whether the number entered is a number using the keyCode in conjunction with the onkeypress event

  • 2020-03-30 01:25:56
  • OfStack

<script language = "javascript" type = "text/javascript"> 
function check(event){ 
//Each time the user presses a key, it determines whether it is a number or not
if(event.keyCode<48 || event.keyCode>57){ 
window.alert(" You're not typing a number! "); 
return false; 
<input type = "text" onkeypress = "return check(event)"/> 

Related articles: