Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with numeric text field in material UI

I am working with material and want to have a numeric input. Using the solution they provide in the documentation isn't working:

<TextField inputProps={{ inputMode: 'numeric', pattern: '[0-9]*' }} />

It looks like a feature for future. But I wanted to know what is the best way to work around numeric input using material ui and only accept number as input. Currently I can type letter in the text field

like image 801
kevin parra Avatar asked Sep 12 '25 08:09

kevin parra


1 Answers

In your case, you can change the inputMode:'numeric' to type:'number' and remove the pattern property. You can try the code snippet like this:

<TextField inputProps={{ type: 'number'}} />

enter image description here

This will only accept number as input.

like image 156
wildgamer Avatar answered Sep 14 '25 21:09

wildgamer