How to validate that a text field doesn't contain a whitespace in flutter? I'm trying to show it on a dialogue
if (_descriptionController2.text.isEmpty) { EasyLoading.showError('Please write a review!');
like this one but i don't know what should i write in the if statement.
CodePudding user response:
try validator work for me here is my code
validator: (value) {
if (value == null || value.isEmpty) {
return '*Required';
}
return null;
},
here is another one only letters
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter your first name';
} else if (!isAlpha(value)) {
return 'Only Letters Please';
}
return null;
CodePudding user response:
Add the following to check for whitespace
if (RegExp(r"\s").hasMatch(_descriptionController2.text)) {
EasyLoading.showError('Text contains whitespace!')
}