React Native TextInput that only accepts numeric characters

前端 未结 19 1136
轮回少年
轮回少年 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:30

    That is the correct way to do it till such a component (or attribute on the TextInput) is specifically developed.

    The web has the ‘number’ type for the input element, but that is web based and react-native does not use a web view.

    You could consider to create that input as a react component on it’s own (maybe call NumberInput): that’ll enable you to reuse it or maybe even open source it since you can create many TextInputs that has different value filters/checkers.

    The downside to immediate correction is to ensure correct feedback is given to the user as to prevent confusion as to what happened to his value

提交回复
热议问题