Search code examples
javascriptdom-events

How do I check if the key pressed on a form field is a digit (0 - 9)?


I'm using the onkeyup event on a form field in JavaScript, and I'm wanting to check if the key the key pressed is a numeric digit - i.e. 0 - 9, so I can then do something with the input.

<input type="text" onkeyup="" />

Would I need to use Regex for this?


Solution

  • See these: