React.js realizes that the input input box only accepts numbers

 

changeEvent=(e)=>{
    let value = e.target.value.replace(/[^\d]/, '')
    this.setState({ checkCode: value })
}

 <input value={this.state.checkCode} onChange={(e) => this.changeEvent(e)></input>

Analysis: [^\d] means all characters except digits, /g means global matching, .replace(/[^\d.]/g,"") means replacing characters other than digits with empty

 

Guess you like

Origin blog.csdn.net/weixin_44745920/article/details/109699681