Validation
This is a validation framework which should help to do basic validations like max length, required etc.
Features
Section titled “Features”Following Validators are available
| Validator | Descriptions |
|---|---|
| BIC | Bic code check if it has the right format |
| Verifies the email format | |
| equals | Compare if two strings are equal. Used for Password check |
| lowercase | Checks if the string is lowercase |
| max_length | Maximal length a string can have |
| max_value | Max value of a double |
| min_value | Min value of a double |
| one_digit | Must be one digit |
| phone | International format of a phone number |
| required | Value must be not null and contain some chars |
| special_character | Checks if a string contains any special characters |
| uppercase | String must be uppercase |
Getting started
Section titled “Getting started”This package uses easy_localization for error messages. Consumer can of course override all the translations globally and define custom message per validator.
This example demonstrates check of the double value. Entered value by user is in this example 50, but max allowed value is 10.
ValidationBuilder<double>() .required() .maxValue(10) .validate(50)Check the mail
Section titled “Check the mail”final validationResult = ValidationBuilder<String>().email().validate("mario#mydomain.com");expect(validationResult, "This is not a valid email address.",reason: "Email is not valid, so a message must be returned");Custom error message
Section titled “Custom error message”final validationResult = ValidationBuilder<String>().email("Mail not ok").validate("mario#mydomain.com");expect(validationResult, "Mail not ok", reason: "Custom message must be used");Translations
Section titled “Translations”in order to generate translation files just run
dart run easy_localization:generate --source-dir assets/translations --source-file en.json --output-dir lib -f keys -o locale_keys_validation.g.dartCustomize translations
Section titled “Customize translations”ValidationBuilder.configuration = Configuration( translation: (translationKey, dynamic currentValue, String? additionalParam, dynamic configValue) { if (translationKey == LocaleKeysValidation.validation_error_value_required) { return requiredTrans; } return null;});© m8ty GmbH 2023 · m8ty.eu
