Main menu:

Site search

Categories

Archive

Limit HTML Text Field To Numbers Only

Using JavaScript to limit which characters can be typed into an HTML input field is very easy. Let’s say you have a field that should only accept numbers in an HTML form. Simply attach an onkeydown event to the <input> element that checks for which key is being pressed. If the key is not valid then the function returns false and the character will not be printed.