Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native - how to key number pad ONLY (without punctuations)

Is there a way to key a numeric keypad without punctuations?

<TextInput keyboardType='numeric' ..... />

if I use secureTextEntry={true}, it gets the right keyboard I want, but the values are replaced with *.

so, this is what im getting:

enter image description here

This is what I want:

enter image description here

like image 616
Raheel Hasan Avatar asked Feb 15 '18 00:02

Raheel Hasan


People also ask

How do you open the number pad in react native?

The <Display> is the number pad's equivalent of React Native's <TextInput> component. It is a controlled component that, when pressed, opens the number pad.

What is key on number pad?

The numpad's keys are digits 0 to 9 , + (addition), - (subtraction), * (multiplication) and / (division) symbols, . (decimal point), Num Lock , and ↵ Enter keys.


2 Answers

I had the same problem.

I could solve doing something like this:

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

and then in a method call from onChangeText doing this:

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

this.setState({
  cleanNumber
});

and it the value prop of TextInput

value={this.state.cleanNumber}
like image 68
Miguel Cardenas Avatar answered Oct 02 '22 02:10

Miguel Cardenas


keyboardType={"number-pad"} Works on Android. Note: I am using FormInput from react-native-elements.

like image 31
Jithesh Kt Avatar answered Oct 02 '22 00:10

Jithesh Kt