Answers for "how to make html input text allow only numeric values"

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
1

html input box integer only

<input type="number" name="someid" />
Posted by: Guest on March-10-2020
0

windows form textbox only allow numbers

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar);
    }
Posted by: Guest on July-12-2021

Code answers related to "how to make html input text allow only numeric values"

Browse Popular Code Answers by Language