All Free <Script>

tips and tricks per webmaster

Consentire l’immissione di solo caratteri numerici

12 Giugno 2017        

A volte si ha la necessità che un campo di input testuale accetti solo l’inserimento di caratteri numerici. Di seguito lo script:

<html>
<head>
	<title>Consentire l'immissione di solo caratteri numerici</title>
	<script type="text/javascript">
	function isNumberKey(evt){
	   var charCode = (evt.which) ? evt.which : event.keyCode
	   if (charCode > 31 && (charCode < 48 || charCode > 57))
	      return false;
	   return true;
	}
	</script>
</head>
<body>
	<input type="text" onkeypress="return isNumberKey(event)">
</body>
</html>