1class App extends React.Component{
2 constructor(){
3 super();
4 this.state = {value: ''};
5 this.onChange = this.onChange.bind(this)
6 }
7
8 onChange(e){
9 const re = /^[0-9\b]+$/;
10 if (e.target.value === '' || re.test(e.target.value)) {
11 this.setState({value: e.target.value})
12 }
13 }
14
15 render(){
16 return <input value={this.state.value} onChange={this.onChange}/>
17 }
18}
19
20ReactDOM.render(<App/>,document.getElementById('app'))