Answer the question
In order to leave comments, you need to log in
Regular expression limiting number to 2 decimal characters?
I am writing a React application, I need a regular expression so that only numbers can be written into the input and after the decimal point you can write a maximum of 2 digits
Here is the code
const FormShopping = observer(() => {
const [inputText, setInputText] = useState('');
function handleInput(e)
{
let text = e.target.value.replace(/[^\d.]{1, 3}/, '');
setInputText(text);
}
})
return (
<Input onInput={handleInput} value={inputText} type="text" />
)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question