Skip to content

Commit

Permalink
Merge pull request #322 from JeevaRamanathan/fix/otp
Browse files Browse the repository at this point in the history
fix: OTP invalid character
  • Loading branch information
sadanandpai authored Nov 2, 2023
2 parents a15c870 + 59df5c3 commit 58db338
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions react/src/machine-coding/otp/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ const App = () => {
let otpinputref = useRef([]);

const handleOtp = (e, index) => {
const numericValue = e.target.value.replace(/[^0-9]/g, '');
const numericValue = e.target.value.replace(/\D/g, '');
const singleDigitValue = numericValue.slice(0, 1);
let copyotpfields = [...otpfields];
copyotpfields[index] = singleDigitValue;
if (index < otpfields.length - 1) {
if (index < otpfields.length - 1 && singleDigitValue) {
otpinputref.current[index + 1].focus();
}
setOtpFields(copyotpfields);
Expand Down Expand Up @@ -61,7 +61,7 @@ const App = () => {
ref={(el) => (otpinputref.current[index] = el)}
onChange={(e) => handleOtp(e, index)}
value={otpfields[index]}
type="number"
type="text"
/>
);
})}
Expand Down

0 comments on commit 58db338

Please sign in to comment.