1
<TextField
                      value={ele.mobile}
                      helperText={ferrors[id]?.mobile}
                      name="mobile"
                      classes={{ root: classes.textField }}
                      InputProps={{ className: classes.textField }}
                      inputProps={{ maxLength: 10, type:'number'}}
                      label="Mobile Number"
                      variant="outlined"
                      onChange={(e) => handleChange(id, e)}
                    />

I have given the values form inputProps of maxLenght and type but only type is working

Hitesh Gn
  • 23
  • 4
  • maxlength and number doesn't work together. `maxlength` only work with text. More details here https://stackoverflow.com/a/18510925/2822041 – Someone Special Jun 13 '22 at 08:15

3 Answers3

1
maybe this will help
 <TextField
 required
 id="required"
 label="Required"
 min={0}
 inputProps={{
    maxLength: 5,
    type: 'number',
}}
onInput={(e)=>{
    e.target.value = Math.max(0, parseInt(e.target.value) ).toString().slice(0,e.target.maxLength)
}}
/>

Narek Grigoryan
  • 369
  • 3
  • 7
0

if you want to make number of lenght max 10, just use max with largest number:

inputProps={{ max: 9999999999, type:'number'}}
Wraithy
  • 1,722
  • 1
  • 5
  • 13
0

About your question, I think you can try to use maxlength setting in inputProps.

<TextField
                      value={ele.mobile}
                      helperText={ferrors[id]?.mobile}
                      name="mobile"
                      classes={{ root: classes.textField }}
                      InputProps={{ className: classes.textField }}
                      inputProps ={{ maxlength: 10, type:'number'}}
                      label="Mobile Number"
                      variant="outlined"
                      onChange={(e) => handleChange(id, e)}
                    />
wildgamer
  • 297
  • 1
  • 3