Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including react-code-input-fixed-build with all npm packages installed. Try it out:

require("react/package.json"); // react is a peer dependency. require("react-dom/package.json"); // react-dom is a peer dependency. var reactCodeInputFixedBuild = require("react-code-input-fixed-build")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

react-code-input-fixed-build v3.9.0

React component for entering and validating numbers, text or password.

react-code-input

React component for entering and validating PIN code.

CircleCI npm version codecov

Live example here

Installation

npm i --save react-code-input

Usage

Numeric input:

Numeric input

...
<ReactCodeInput type='number' fields={6} />
...

Text input:

Text input

...
<ReactCodeInput type='text' fields={6} />
...

Password input:

Password input

...
<ReactCodeInput type='password' fields={6} />
...

Numeric input with options:

Numeric input with options

import { reactCodeInput } from 'CodeInputField.scss'
...
const props = {
  className: reactCodeInput,
  inputStyle: {
    fontFamily: 'monospace',
    margin:  '4px',
    MozAppearance: 'textfield',
    width: '15px',
    borderRadius: '3px',
    fontSize: '14px',
    height: '26px',
    paddingLeft: '7px',
    backgroundColor: 'black',
    color: 'lightskyblue',
    border: '1px solid lightskyblue'
  },
  inputStyleInvalid: {
    fontFamily: 'monospace',
    margin:  '4px',
    MozAppearance: 'textfield',
    width: '15px',
    borderRadius: '3px',
    fontSize: '14px',
    height: '26px',
    paddingLeft: '7px',
    backgroundColor: 'black',
    color: 'red',
    border: '1px solid red'
  }
}
...
<ReactCodeInput type='number' fields={6} {...props}/>
...

Usage with next.js

import dynamic from 'next/dynamic';

const ReactCodeInput = dynamic(import('react-code-input'));
...
<ReactCodeInput type='number' fields={6} {...props}/>
...

Props:

PropertyTypeDescription
typestringOnly types like: text, number, password and tel are accepted.
fieldsnumberAllowed amount of characters to enter.
valuestringSetting the value of code input field.
namestringSetting the name of component.
onChangefuncFunction, which is called whenever there is a change of value in the input box.
touchfuncMarks the given fields as "touched" to show errors.
untouchfuncClears the "touched" flag for the given fields.
classNamestringAdd classname to the root element.
styleobjectSetting the styles of container element.
inputStyleobjectSetting the styles of each input field.
inputStyleInvalidobjectSetting the styles of each input field if isValid prop is false.
isValidboolReturns true if an input element contains valid data.
disabledboolWhen present, it specifies that the element should be disabled.
autoFocusboolSetup autofocus on the first input, true by default.
filterKeyCodesarrayFilter characters on key down.
filterCharsarrayFilter characters; default is ['-', '.']
filterCharsIsWhitelistboolfilterChars acts as blacklist if false, whitelist if true; false by default.
patternstringThe pattern prop specifies a regular expression that the element's value is checked against.
inputModestringThe inputMode prop tells the browser on devices with dynamic keyboards which keyboard to display.

Compatible with

redux-form from erikras

next.js from zeit

License

MIT

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free