React Native TextInput that only accepts numeric characters

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

    Here is my other simple answer to accept only numbers in the text box using Regular Expressions.

    onChanged(text){
        this.setState({ 
             myNumber: text.replace(/[^0-9]/g, '') 
        });
    }
    

提交回复
热议问题