Categories
JavaScript Answers React Native Answers

How to set max length of the TextInput with React Native?

Spread the love

Sometimes, we want to set max length of the TextInput with React Native.

In this article, we’ll look at how to set max length of the TextInput with React Native.

How to set max length of the TextInput with React Native?

To set max length of the TextInput with React Native, we can set the maxLength prop.

For instance, we write:

import * as React from 'react';
import { TextInput, View } from 'react-native';
import Constants from 'expo-constants';
import { Card } from 'react-native-paper';

export default function App() {
  const [text, setText] = React.useState();

  return (
    <View>
      <TextInput value={text} onChangeText={setText} maxLength={10} />
    </View>
  );
}

to set the maxLength prop to 10 to allow users to enter a max of 10 characters into the input.

Conclusion

To set max length of the TextInput with React Native, we can set the maxLength prop.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *