I am using Textinput from react-native. How can I paste the otp or code automatcally in the textinput box.
6 Answers
As of react native version 0.66+
Android: Can use the autocomplete set to sms-otp
iOS: Can use textContentType set to oneTimeCode

- 6,413
- 6
- 34
- 57
To paste otp automatically from sms in your iOS app in react-native you need to do following steps:
- Set textContentType="oneTimeCode"(supported only for iOS devices):
- You need to Send sms with the following pattern: <#> code: your otp here.
for e.g we send an sms in your company like this: <#> code: 1234.
P.S. I also have autoFocus = {true} on my otp input.
You can use the "oneTimeCode"
For example:
<TextInput style={TEXTHEADER} textContentType="oneTimeCode" />
Online reference:

- 98
- 1
- 8
If anyone else is looking for how to do this in React Native web in a mobile browser, you do not need textContentType since this is an iOS only prop. You can do it by simply auto focusing your input. The code will autofill to whatever input is focused when the user taps on the code.
<TextInput
autoFocus={true}
value={value}
caretHidden={true}
onChangeText={onChangeText}
keyboardType="number-pad"
/>

- 11
- 4
You have to put textContentType="oneTimeCode"
and keyboardType="numeric"
on your TextInput
. [EDIT 2023-01-22] some people (@TaiyrBegeyev) says that it's keyboardType="number-pad"
instead, I couldn't try it again so... your move !
If you need to handle the code, also add a onChangeText
prop to the TextInput
and FINALLY, the most important, if you don't see iOS poping up your code coming from SMS, check which message you're sending. In my case, in French,
Veuillez saisir le code ${code} dans l'application
is workingVeuillez entrer ce code dans l'application : ${code}
is NOT working
I've been checking RN side for hours, and finally changing the SMS was the solution.

- 2,403
- 3
- 25
- 51
-
It works for me when I use `textContentType="oneTimeCode"`, but does not work when I add `keyboardType="numeric"`. – MikeyE Jul 27 '21 at 05:21
-
2@MikeyE the `keyboardType` field should be `number-pad` instead. – Taiyr Begeyev Jan 21 '23 at 16:49
-
I trust you @TaiyrBegeyev I update my answer – arnaudambro Jan 22 '23 at 19:12
Easiest way is to use SMS listening built in packages.
https://www.npmjs.com/package/react-native-android-sms-listener
https://www.npmjs.com/package/react-native-otp-verify
If you're using react-native-android-SMS-listner package, you can use a code as follows.
let subscription = SmsListener.addListener(message => {
let verificationCodeRegex = /Your verification code: ([\d]{6})/
if (verificationCodeRegex.test(message.body)) {
let verificationCode = message.body.match(verificationCodeRegex)[1]
YourPhoneVerificationApi.verifyPhoneNumber(
message.originatingAddress,
verificationCode
).then(verifiedSuccessfully => {
if (verifiedSuccessfully) {
subscription.remove()
return
}
if (__DEV__) {
console.info(
'Failed to verify phone `%s` using code `%s`',
message.originatingAddress,
verificationCode
)
}
})
}
})
If youre using react-native-otp-verify you can follow the following tutorial
Hope this helps

- 699
- 1
- 7
- 13