I have an Input field to which I want user to be able to enter only number/decimal values up to 2 decimal places. User should not be able to enter any alphabet. Can someone please help me with this
My React Component:
import React from 'react'
import { useState } from "react";
function LoanCalc() {
const [amount, setAmount] = useState();
const handleChange = (event) => {
}
return (
<div className="Container">
<div className="LoanAmount">
<label>Loan Amount:</label>
<span>$
<input type="text" min="4000" max="100000" value={amount} onChange={handleChange}/>
</span>
</div>
</div>
);
}
export default LoanCalc
check this codesandbox example
https://codesandbox.io/s/xo2x1qnw0w
additional to not restricting any invalid input this will round off if there is more decimal point