score:0

$('#score').keypress(function(e){
    var code = (e.which) ? e.which : e.keyCode;
    if($('#' + e.target.id).val().length > 2)
        e.preventDefault();
    if (code > 31 && (code < 48 || code > 57)) {
        e.preventDefault();
    }
});

score:0

<TextField
  id="score"
  label="score"
  className={classes.textField}
  name="totalScore"
  margin="normal"
  value={this.state.score}
  onChange={this.handleChange.bind(this)}
/>

score:0

             <TextField
              id="number"
              placeholder="Enter Number"
              type="number"
              value={state.count}
              onChange={(event) => {
                const regex = /^([0-9]){minLength,maxLength}$/;
                if (event.target.value === '' || regex.test(event.target.value)) {
                  setState({ ...state, count: event.target.value });
                }
              }}
              variant="outlined" />

score:0

<TextField
   value={phone}
   onChange={event => setPhone(event.target.value)}
   variant="outlined"
   placeholder={'Phone number'}
   type={'number'}
   onInput={(e)=>{e.target.value = Math.max(0, parseInt(e.target.value)).toString().slice(0,10)}}
   min={0} 
/>

score:3

<TextField type="number"
    className="text-field-amount"
    onInput={(e)=>{ 
        e.target.value = Math.max(0, parseInt(e.target.value) ).toString().slice(0,2)
    }}
    min={0}
/>

score:5

<TextField
  id="score"
  label="score"
  name="totalScore"
  style={style.filedStyle}
  inputProps={{ min: 3, max: 3}}
/>

Related Query

More Query from same tag