4

My goal is to get ONLY numeric keyboard without punctuation. number-pad is not working properly on every device and it also allows to enter symbols "-, _." that is not what I want. I noticed that when secureTextEntry is set to true on TextInput the keyboard is just the one I want, but I can't use it like this because my text is getting masked. So I wonder is there a way to use that keyboard without masking the text? Maybe a hack in the native code exists?

The screen of desired keyboard enter image description here

NUMBER-PAD IS NOT WORKING ON EVERY DEVICE! THIS IS NUMBER-PAD ON HONOR 8X enter image description here

6 Answers 6

4

You can try by doing like this- keyboardType={Platform.OS === 'android' ? "numeric" : "number-pad"} and then in a method call from onChangeText do this:

**const trimNumber = number.replace(/[^0-9]/g, "");

this.setState({ trimNumber });**

and it is the value prop of TextInput

value={this.state.trimNumber}

By this user wont be able to give any punctuation, if any, we are restricting to enter.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! But number-pad is different on Honor 8x so it may be different on other devices (see pinned screenshot). Also cutting non numerical values from the string programmatically leads to symbol being visible for half a second before it deleted, It can be dealt with setting value through setNativeProps but why do that if we can find a way to use "secure" keyboard and be happy
3

You may try below :

keyboardType={Device.isAndroid ? "numeric" : "number-pad"}

and for more : click here

4 Comments

Thank you! But number-pad is deferent on Honor 8x so it may be different on other devices (see pinned screenshot). We need to find a better approach
sure! give me the time for do R&D on this! i'll let you know. thanks for you vote up!
I have found that the keyboard inputType is used in react-native/ReactAndroid/src/main/react/views/textinput/ReactEditText.java, line 771 and in ReactTextInputManager.java, line 102, but it seems that to see the changes we need to compile it github.com/facebook/react-native/wiki/Building-from-source
Also this issue may be helpful github.com/facebook/react-native/issues/4090
2

As per the docs ,

You can achieve this by doing :

keyboardType={Platform.OS === 'ios'? "number-pad":"numeric"}

Hope it helps . feel free for doubts

1 Comment

Thank you! But number-pad is deferent on Honor 8x so it may be different on other devices (see pinned screenshot). We need to find a better approach
1

To show numeric pad in IOS same a pic in an original question. And use the returnKeyType at the same time.

keyboardType={Platform.OS === 'android' ? "numeric" : "numbers-and-punctuation"}

Comments

1

Try

<Input keyboardType= 'phone-pad'/>

it worked for me.

or for both android & ios or something else

 <Input keyboardType= {Platform.OS === 'android' ? 'phone-pad' : (Platform.OS ==='ios'?'number-pad' :'numbers-and-punctuation')} />

you can check the documentation here react-native keyboardType

Comments

-1

This keyboard only available for secureText secureTextEntry={true}

Code

<Input keyboardType={Device.isAndroid ? "numeric" : "number-pad"}
       secureTextEntry={true} />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.