Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Textinput minimum length React native

Is there a way to limit the textinput between a minimum length and maximum length. Suppose I want to limit the textinput length between 5 and 15, how do I do that ?

like image 332
Vinay N Avatar asked Oct 15 '25 07:10

Vinay N


1 Answers

Consider adding the following code in your component:

<TextInput onTextChange={this.onTextChange} maxLength={15} ... />
<Button onPress={this.onPress} ... >Submit</Button>

onTextChange = text => {
   this.setState({text : text});
}

onPress = () => {
   const {text} = this.state;

   if(text.length < 5) {
      console.log('Your text is less than what is required.');
   }
}
like image 113
arjayosma Avatar answered Oct 18 '25 09:10

arjayosma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!