I have two text fields, one of them should be year so I want to allow only enter numbers between 1900 and 2020, second one for ratings and it should be 9.9 at most and it can be 5 or 5.5 etc, When I use below code, I can get 1800 or 3450 in year field and rating side can be 123 or anything has 3 digits. Is there any way to restrict them as just like I want?
For years;
new TextField(
controller: _disControllerF,
textAlign: TextAlign.center,
style: new TextStyle(
fontWeight: FontWeight.w400,
fontFamily: "SegoeUI",
fontStyle: FontStyle.normal,
fontSize: 16.0
),
keyboardType: TextInputType.number,
inputFormatters:<TextInputFormatter>[
LengthLimitingTextInputFormatter(4),
WhitelistingTextInputFormatter.digitsOnly,
],
decoration: InputDecoration(
border: new OutlineInputBorder(
),
hintText: '1900',
hintStyle: TextStyle(
fontWeight: FontWeight.w400,
fontFamily: "SegoeUI",
fontStyle: FontStyle.normal,
fontSize: 16.0),
contentPadding: const EdgeInsets
.symmetric(
horizontal: 10.0),
),),
For ratings;
new TextField(
controller: _disControllerR,
textAlign: TextAlign.center,
style: new TextStyle(
fontWeight: FontWeight.w400,
fontFamily: "SegoeUI",
fontStyle: FontStyle.normal,
fontSize: 16.0
),
keyboardType: TextInputType.number,
inputFormatters:<TextInputFormatter>[
LengthLimitingTextInputFormatter(3),
WhitelistingTextInputFormatter(RegExp("[1-9.]")),
],
decoration: InputDecoration(
border: new OutlineInputBorder(
),
hintText: '6.5',
hintStyle: TextStyle(
fontWeight: FontWeight.w400,
fontFamily: "SegoeUI",
fontStyle: FontStyle.normal,
fontSize: 16.0),
contentPadding: const EdgeInsets
.symmetric(
horizontal: 10.0),
),),