Ali Zeynalov
Ali Zeynalov

Reputation: 3027

make the content of a button in keyboard empty - react-native

I am using numeric keyboard in my program and I need to set one of the buttons on the keyboard empty - "." button should not exist, I just need numbers. How I can do it?

Thanks in advance.

Upvotes: 1

Views: 144

Answers (2)

BradByte
BradByte

Reputation: 11093

If you want to use the native keyboard but disable the effect of non-numeric buttons, you could do something like this:

handleTextChange(text) {
  // remove non-numbers using regex
  text = text.replace(/\D/igm, '')
  this.setState({number: text})
}
...
<TextInput
  value={this.state.number}
  keyboardType="numeric"
  onChangeText={this.handleTextChange.bind(this)}
  ...
/>

Basically you're using the onChangeText call to catch the text change and then using the "not digit" regex selector \D you replace it with empty string.

Upvotes: 0

Gui Herzog
Gui Herzog

Reputation: 5615

If you are using a native keyboard, you cannot do this.

If you still want to do it, maybe you should create your own keyboard or look for a library with a customizable one.

Upvotes: 1

Related Questions