Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

numbers-only

luisfcolon7MIT1.0.3

Javascript event to only allow numbers in an input field

javascript, events, number, numbers only, form, input, is numeric

readme

Numbers Only

Build Status Coverage Status GitHub license NPM downloads GitHub issues

Overview

Javascript event handler to only allow numbers and a few special characters.

Works with text and number input types.

Allows the following characters:

  • tab
  • del
  • left-arrow
  • right-arrow
  • 0 - 9 using standard keyboard
  • 0 - 9 using a numberpad

Installation

Using npm

npm install numbers-only

Using yarn

yarn add numbers-only

Usage

It works best when you use numbersOnly as the event handler for keydown events.

import numbersOnly from 'numbers-only';


<input type="text" name="some-numeric-field" onkeydown="numbersOnly" />