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.
Asked
Active
Viewed 5,365 times
4
-
This might help you [check here](https://stackoverflow.com/questions/52835450/flutter-how-to-avoid-special-characters-in-validator) – Jahanvi Kariya Nov 01 '19 at 06:46
-
i am asking about multiple validations, like 2 or more validations in textformfield. i have created 2 methods for validations. one for field required and other for checking that inputs should be only alphabets. i want to perform these 2 validation on textFormField at the same time. – Dinesh kumar Nov 01 '19 at 07:00
1 Answers
7
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

chunhunghan
- 51,087
- 5
- 102
- 120
-
-
Hi, i couldn't use the commands you writed. some of them out dated i suppose? look like attribute became name. – Tim's Dec 27 '21 at 15:29