Get code from sms in React Native
01 February 2023
I am releasing a book about the React Native ecosystem, which covers everything I wish I had known before I started working with this technology.
If you appreciate my work and would like to show your support, please check the Road to React Native.
How to autofill code from messages
When working with forms that require you to enter a code sent to you via text message, make sure to include a prop called "textContentType" with a value of "oneTimeCode" for iOS, and you can complete with "autoComplete" and "one-time-code". This will help the form recognize the code you enter, and automatically fill the TextInput.
It can be used for various purposes, such as:
- SMS codes
- SMS text messages
- SMS login codes
- Apple ID codes
- Two-factor authentication
- Verification codes
For iOS 12+, the oneTimeCode attribute can be used to indicate that a field can be auto-filled by a code arriving in an SMS.
import { TextInput } from 'react-native';
<TextInput
textContentType="oneTimeCode"
autoComplete="one-time-code"
...
/>
Reference
Hi, I’m David, a french freelance developer working remotely. I’m the author of this blog, nice to meet you!
Subscribe?
Be the first to receive insightful articles and actionable resources that help you to elevate your skills.