I would handle the ban symbol in the onChange handler. One reason: what happens if someone copies and pastes something into your input? Preventing input in the keyboard event handler will not work.
I would try something like this:
handleChange(e) { // Use whatever regex you need. const filteredInput = e.target.value.replace(/[abAB$&()-_.*]|\d+/g, ''); this.setState(value: filteredInput) }
And then use it to enter.
<input id="username" type="text" placeholder="Username" value={this.state.value} onChange={this.handleChange.bind(this)} />
source share