React Native TextInput that only accepts numeric characters

前端 未结 19 1097
轮回少年
轮回少年 2020-12-02 10:38

I need to have a React Native TextInput component that will only allow numeric characters (0 - 9) to be entered. I can set the keyboardType to

19条回答
  •  失恋的感觉
    2020-12-02 11:41

    React Native TextInput provides keyboardType props with following possible values : default number-pad decimal-pad numeric email-address phone-pad

    so for your case you can use keyboardType='number-pad' for accepting only numbers. This doesn't include '.'

    so,

     this.onChanged(text)}
      value = {this.state.myNumber}
    />
    

    is what you have to use in your case.

    for more details please refer the official doc link for TextInput : https://facebook.github.io/react-native/docs/textinput#keyboardtype

提交回复
热议问题