This question and its answers have been closed.
Asked
Active
Viewed 23 times
3 Answers
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>
Harunur Rashid
- 31
- 1
- 6