0

Basically, input field should accept only 1 - 999 values

Input Field :

<input
  type="number"
  value={value}
  onChange={this.props.onViltMaxUserChange}
  min="0"
  max="999"
/>

onChange :

  onViltMaxUserChange = _.throttle(e => {
    let { value, min, max } = e.target;
    if (value !== '' && !(_.inRange(value, min, max))) return false
    this.setState({ value: value });
  }, 50);

But User is able to add ---- or ++++ onChange is not triggered when user inputs + or -. I Don't want to allow user to input these.

How can I do this ?

vikas95prasad
  • 1,234
  • 1
  • 12
  • 37
  • Does this answer your question? [ReactJs prevent e and dot in an input type number](https://stackoverflow.com/questions/45834885/reactjs-prevent-e-and-dot-in-an-input-type-number) – Yannick K Feb 21 '20 at 09:24
  • add this event : - onKeyDown={(evt) => ["e", "E", "+", "-"].includes(evt.key) && evt.preventDefault()} – niks Feb 21 '20 at 09:24

1 Answers1

0

You could validate your input value with regular expression /^[0-9]{1,3}$/.test(value) in onKeyUp event.

Sdwdaw
  • 1,037
  • 7
  • 14