I want to Build a TextField in Flutter in which the user must type in his name, but I want to force him to input a minimum of 2 characters.
This is my code:
TextField(
autofocus: true,
textCapitalization: TextCapitalization.words,
textAlign: TextAlign.center,
decoration: InputDecoration(
labelStyle: TextStyle(color: Colors.blue[900]),
border: InputBorder.none,
hintText: 'VORNAME',
),
style: TextStyle(
color: Colors.blue[900],
fontWeight: FontWeight.w600,
fontSize: MediaQuery.of(context).size.width * 0.075),
cursorColor: Colors.greenAccent,
inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter(RegExp("[a-zA-ZÄäÖöÜü]")) //Only Text as input
],
onChanged: (value) {
userData.forename = value;
},
onSubmitted: (value) {
Navigator.of(context).push(
CupertinoPageRoute(builder: (context) => SurName()));
}),
How can I achieve this? Thank you in advance!
Ben