| Javascript | HTML | Browsers | Client Side | Web |
SummaryHere I show how to use Javascript to allow only numbers to be entered in a textbox. This is useful for phone numbers, IDs, ZipCodes, and, well, that's about it.
This solution works in both IE and Netscape/Mozilla.
Try it here! Just type in the text box below. Note that digits are allowed and alphabetic characters are not allowed. Observe, too, that arrow keys and backspace _are_ allowed so that you can still edit what you type.
|
Example: Allow only numbers/digits in TextBox<HTML>
<HEAD>
<SCRIPT language=Javascript>
</SCRIPT>
</HEAD>
<BODY>
<INPUT id="txtChar" onkeypress="return isNumberKey(event)" type="text" name="txtChar">
</BODY>
</HTML> |
|