Package selection guidance compiled from public package information, community data, and project usage.
form_validator is a lightweight and intuitive package for validating form fields in Flutter applications. It provides a simple API to define validation rules such as required fields, email format, length constraints, and custom validators. Designed specifically for Flutter's FormField widgets, it streamlines the process of ensuring user input meets specified criteria without boilerplate code. The library integrates seamlessly with existing forms and supports multiple platforms including Android, iOS, Web, macOS, Windows, and Linux.
Use cases
Validating user registration forms
Checking email and password inputs
Ensuring field length requirements
Implementing custom validation logic
Simplifying form state management
Key features
Minimal setup and configuration
Supports required, email, length, and custom validators
Now you can use ValidationBuilder class to create validation logic. Here's simple validator that validates if input length is between 10 and 50 characters long.
final validate = ValidationBuilder().minLength(10).maxLength(50).build();
print(validate('test')); // Minimum length must be at least 10 charactersprint(validate('Hello World')); // null, means value is correct
Localization
You can set global locale using ValidationBuilder.setLocale(String localeName)
or you can also define locale on ValidationBuilder({ String localeName }) constructor.
ValidationBuilder.setLocale('en');
// will use *en* localizationValidationBuilder()
.minLength(5)
.build();
// will use *az* localizationValidationBuilder(localeName: 'az')
.minLength(5)
.build();
// will display custom messageValidationBuilder()
.minLength(5, 'Length < 5 😟')
.build();
Methods
.minLength(int minLength, [String message])
Validates if value length is not less than minLength.
.maxLength(int maxLength, [String message])
Validates if value length is not more than maxLength.
.email([String message])
Checks if value is an email address.
.phone([String message])
Checks if value is an phone number.
Note: This method might be changed in future.
.ip([String message])
Checks if value is correct IPv4 address.
.ipv6([String message])
Checks if value is correct IPv6 address.
.url([String message])
Checks if value is correct url address.
.match(String otherValue, [String message])
Checks if the value matches the specified otherValue. This can be used to validate if two input values are identical.
Validates if value passes any of left and right validations. If value doesn't passes any error message from right validation will be displayed (If reverse set to true message from left validation will be displayed).