Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Input component takes ony numeric values

In React-Native project, I have an Input component from Native Base and I want to this component to take only numeric values 0-9 and give this field default value, I looked for other questions about this issue, I do not know maybe those answers are for 'textInput' component or somehow suggestions did not work for me? Can you help me please?

like image 711
Ali Zeynalov Avatar asked Nov 16 '16 11:11

Ali Zeynalov


2 Answers

try use

keyboardType="numeric"

source

like image 140
Muhammad Rosyid Avatar answered Oct 05 '22 17:10

Muhammad Rosyid


I grab your problem there is no attribute for Text Input to take numeric only. But I have two method for this, In first method you have to write the code for taking the value numeric this is hack but you can use it, the code is :

        <TextInput 
          style={styles.textInput}
          keyboardType = 'numeric'
          onChangeText = {(text)=> this.onChanged(text)}
          value = {this.state.myNumber}
        /> 

        onTextChanged(text) {
          // code to remove non-numeric characters from text
          this.setState({myNumber: text})
        }

For second Method use this:

like image 26
Anuj Kumar Avatar answered Oct 05 '22 17:10

Anuj Kumar