1 <input type="text" pattern="[0-9]*"
2 onInput={this.handleChange.bind(this)} value={this.state.financialGoal} />
1// Validation with REGEX
2const rx_live = /^[+-]?\d*(?:[.,]\d*)?$/;
3
4class TestForm extends React.Component {
5 constructor() {
6 super();
7 this.state = {
8 depositedAmount: ''
9 };
10 }
11
12 handleDepositeAmountChange = (evt) => {
13 if (rx_live.test(evt.target.value))
14 this.setState({ depositedAmount : evt.target.value });
15 }
16
17 render() {
18 return (
19 <form>
20 <input
21 type="text"
22 id="depositedAmount"
23 maxLength={9}
24 pattern="[+-]?\d+(?:[.,]\d+)?"
25 placeholder="Enter amount"
26 onChange={this.handleDepositeAmountChange}
27 value={this.state.depositedAmount}
28 />
29 </form>
30 )
31 }
32}
33