
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react18-input-otp
Advanced tools
A fully customizable, one-time password (OTP) and phone number with separator input component for the web built with React.
A fully customizable, one-time password (OTP) and phone number with separator input component for the web built with React. Tested on Web, Android, and iOS. This package supports all react versions.

npm install --save react18-input-otp
import React, { Component } from 'react';
import OtpInput from 'react18-input-otp';
export default class App extends Component {
state = { otp: '' };
handleChange = (otp) => this.setState({ otp });
render() {
return <OtpInput value={this.state.otp} onChange={this.handleChange} numInputs={6} separator={<span>-</span>} />;
}
}
import React, { useState } from 'react';
import OtpInput from 'react18-input-otp';
export default function ReactOtpInput() {
const [otp, setOtp] = useState('');
const handleChange = (enteredOtp) => {
setOtp(enteredOtp);
};
return <OtpInput value={otp} onChange={handleChange} numInputs={6} separator={<span>-</span>} />;
}
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| id | string | false | none | Provide unique id for your OTP input. |
| numInputs | number | true | 4 | Number of OTP inputs to be rendered. |
| onChange | function | true | console.log | Returns OTP code typed in inputs. |
| onSubmit | function | false | console.log | Returns OTP code on submit. This allows to submit the OTP on enter key too. |
| value | string / number | true | '' | The value of the OTP passed into the component. |
| placeholder | string | false | none | Specify an expected value of each input. The length of this string should be equal to numInputs. |
| separator | component | false | none | Provide a custom separator between inputs by passing a component. For instance, <span>-</span> would add - between each input. |
| separateAfter | number | false | 1 | Provide the count to set the separater after every input. For instance, 3 would add - after every third input. |
| autoComplete | string | false | off | Provide the autocomplete feature for the input. Now, supports one-time-code as autoComplete. |
| ariaLabelOverride | string | false | none | Provide the custom arialabel for the input. |
| containerStyle | style (object) / className (string) | false | none | Style applied or class passed to container of inputs. |
| inputStyle | style (object) / className (string) | false | none | Style applied or class passed to each input. |
| focusStyle | style (object) / className (string) | false | none | Style applied or class passed to inputs on focus. |
| isDisabled | boolean | false | false | Disables all the inputs. |
| disabledStyle | style (object) / className (string) | false | none | Style applied or class passed to each input when disabled. |
| hasErrored | boolean | false | false | Indicates there is an error in the inputs. |
| errorStyle | style (object) / className (string) | false | none | Style applied or class passed to each input when errored. |
| isSuccessed | boolean | false | false | Indicates there is success with the inputs.. |
| successStyle | style (object) / className (string) | false | none | Style applied or class passed to each input when success. |
| shouldAutoFocus | boolean | false | false | Auto focuses input on initial page load. |
| isInputNum | boolean | false | false | Restrict input to only numbers. |
| isInputSecure | boolean | false | false | Masks input characters. |
| data-cy | string | false | - | Test attribute passed to the inputs. |
| data-testid | string | false | - | Test attribute passed to the inputs. |
| custom-test-id | string | false | - | Custom test attribute passed to the inputs. |
| custom-test-attr | string | false | - | Custom test attribute passed to the inputs. |
| inputProps | InputHTMLAttributes | InputHTMLAttributes[] | false | - | Custom input props. |
npm run dev
Feel free to open issues and pull requests!
Special Thanks to devfolioco. This project is build on top of react-otp-input.
This project follows the all-contributors specification. Contributions of any kind welcome!
FAQs
A fully customizable, one-time password (OTP) and phone number with separator input component for the web built with React.
The npm package react18-input-otp receives a total of 16,996 weekly downloads. As such, react18-input-otp popularity was classified as popular.
We found that react18-input-otp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.