i wanted to allow only digits with decimal on react input and do some condition based on the value got, below what i tried which works fine but with problem mentioned below
<FormInput
name="amount"
label="Amount"
onChange: this.handleChange,
startAdornment: (<InputAdornment position="start">$</InputAdornment>),
pattern: '[0-9]*',
/>
handleChange = (event) => {
const { value } = event.target;
const validValue = Math.abs(parseFloat(value));
if (validValue && !isNaN(validValue)) {
// some condition...
// i have some other set of value that i compare here with input got like if
// 1) validValue > someValue, then this.setState({ someValue })
// 2) validValue <= someValue, then this.setState({ validValue })
// 3) else this.setState({ validValue: 0 })
}
}
But the problem here is i am not able to enter decimal along with other digits, like i need to enter 1.2 then first i need to enter 12 and then add '.'(decimal) before 2, so please help me what i can do to allow digits with decimal along other digits