Answers for "How to make the input field only accept numbers in js"

5

accept only numbers in textbox

<input type="text" onkeypress="return isNumberKey(event)" placeholder="Phone Number">
//this will accept only numbers from 0 to 9
<script>
function isNumberKey(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
	return false;

	return true;
}
</script>
Posted by: Guest on December-19-2020

Code answers related to "How to make the input field only accept numbers in js"

Browse Popular Code Answers by Language