Reputation: 57
how to validate that my text fields has characters [a-z]?
TextFormField(
maxLines: 20,
maxLength: 200,
controller: _descriptionController2,
decoration: InputDecoration(
contentPadding:
EdgeInsets.only(left: 10.0, top: 16.0),
hintText: "What do you think about the place?",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(16.0)),
),
),
Upvotes: 1
Views: 1218
Reputation: 1747
You can use
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.allow(RegExp('[a-z]'))
],
Upvotes: 1
Reputation: 626
You can use regex on TextFormField validator:
TextFormField(
validator: (value) {
final RegExp regex = RegExp('[a-zA-Z]');
if (value == null || value.isEmpty || !regex.hasMatch(value)) {
return 'Must have letters';
}
return null;
},
),
This regex will check if have at least one letter on your string.
Upvotes: 0