React Native Input component takes ony numeric values

荒凉一梦 提交于 2019-12-08 18:24:26

问题


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?


回答1:


try use

keyboardType="numeric"

source




回答2:


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:




回答3:


keyboardType="number-pad"

see source https://facebook.github.io/react-native/docs/textinput.html#keyboardtype



来源:https://stackoverflow.com/questions/40630918/react-native-input-component-takes-ony-numeric-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!