-
-
Save AlexisLeon/80b5641eb30b43bc598288e41052ac39 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'; | |
import { TextInput } from 'react-native'; | |
class Input extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
text: '' | |
}; | |
} | |
handleInputChange = (text) => { | |
if (/^\d+$/.test(text)) { | |
this.setState({ | |
text: text | |
}); | |
} | |
} | |
render () { | |
return ( | |
<TextInput | |
keyboardType='numeric' | |
onChangeText={this.handleInputChange} | |
value={this.state.text} | |
/> | |
) | |
} | |
} |
Nice snippet, I tried the code and discovered a bug though. You can't set the text back to blank. Here is how i changed the code
if (/^\d+$/.test(amount) || amount === '') { this.setState({ amount }) }
thanks
thanks!
and @gate3 too for updated code
Thanks
what about
-5
.2
0.5
-0.5
It ain't working!!!
It's working! Thx!
Nice snippet, I tried the code and discovered a bug though. You can't set the text back to blank. Here is how i changed the code
if (/^\d+$/.test(amount) || amount === '') { this.setState({ amount }) }
this works great!!!
How can we do the same for Input Field
in React Native. Please find my sample code :
CODE:
ONCHANGETEXT CODE`::
Nice snippet, I tried the code and discovered a bug though. You can't set the text back to blank. Here is how i changed the code
if (/^\d+$/.test(amount) || amount === '') { this.setState({ amount }) }
Great, this works excellent
Thanks
This was very helpful
Thanks...this is great!