0

This question and its answers have been closed.

3 Answers3

0

Try this

<input type="number" min="1" step="any" />
0

With regex you can use that:
^[^0]\d+" And add the rest of your usage, this will avoid 0 being in the begining. [^] match any character that is not in the set - so putting 0 inside will avoid the first char to be 0 (with [^0]).

LironShirazi
  • 326
  • 1
  • 7
0

class Example extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      financialGoal: ''
    }
  }
  
  handleChange(evt) {
    const financialGoal = (evt.target.validity.valid) ? evt.target.value : this.state.financialGoal;
    
    this.setState({ financialGoal });
  }
  
  render() {
    return (
      <input type="number" pattern="[0-9]*" min="1" step="any" onInput={this.handleChange.bind(this)} value={this.state.financialGoal} />
    )
  }
}
  
ReactDOM.render(<Example />, document.body);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>