Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do multiple validations on TextFormField in flutter? [closed]

Tags:

flutter

I want to perform multiple validations in TextFormField in flutter like field required validation, only alphabets validations or only numbers validation etc at the same time. Please suggest any idea. Thanks in advance.

like image 406
Dinesh kumar Avatar asked Oct 28 '25 23:10

Dinesh kumar


1 Answers

Package https://pub.dev/packages/flutter_form_builder support build in validators https://pub.dev/packages/flutter_form_builder#built-in-validators such as
FormBuilderValidators.required() - requires the field have a non-empty value.
FormBuilderValidators.numeric() - requires the field's value to be a valid number.

you can put two or more validate in validators attributes,
code snippet

FormBuilderTextField(
  attribute: "age",
  decoration: InputDecoration(labelText: "Age"),
  validators: [
    FormBuilderValidators.numeric(errorText: "La edad debe ser numérica."),
    FormBuilderValidators.max(70),
  ],
),

example code https://github.com/danvick/flutter_form_builder/blob/master/example/lib/main.dart

working demo

enter image description here

like image 154
chunhunghan Avatar answered Oct 30 '25 15:10

chunhunghan