text_form_validator

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

text form validator

Form Validator #
This package is intended to help create informative validation for flutter
form fields.
Features #
The FormValidator class is intended to be used to chain validation
functions together to produce one validator function as required by Widgets
such as TextFormField. The final closure using the build method matches
the type required by the validator attribute for form fields "String? Function(String?)".
Getting started #
To use this package add text_form_validator as a package in your pub file.
Usage #
import "package:text_form_validator/form_validator.dart";
// Basic, the field can't be null or empty
TextFormField(validator: FormValidator.required().build());

// All the messages which will be returned from validation can't be cusomtised
// as required. Each validator is run one after the other, so the message
// to the end user can be as specific as possible
TextFormField(validator: FormValidator
.notNull(nullError: "Woah enter something!")
.notEmpty()
.isNumeric()
.build());

// More complex validation can also be added on the fly
String customError = "Number must be a multiple of 100!";

ValidationFn validator = FormValidator
.notNull(nullError: "Woah enter something!")
.notEmpty()
.isNumeric()
// If it hits the custom we can assume the types will convert properly
.custom((p0) => (p0 == null || (num.parse(p0) % 100) != 0) ? customError : null)
.build();

TextFormField(validator: validator);
copied to clipboard
Current Default Functions #
Below is a list of all current default functions provided, as specified these
are here to assist the user, and may not be exhaustive, see FormValidator.custom
for adding custom functions. The descriptions provided here are brief, check the
functions themselves in utils/string_validation_functions.dart for full details.
Default Functions List #

notNull: Not equal to null
notEmpty: Not equal to ""
required: Combines notNull and notEmpty
isNumeric: num.tryParse != null
isDateTime: The value can be formatted into a date (can specify custom format)
equals: == provided value
notEquals: != provided value
lengthGt: value.length > providedValue
lengthGtEq: value.length >= providedValue
lengthLt: value.length < providedValue
lengthLtEq: value.length <= providedValue
lengthEq: value.length == providedValue
inList: The value is in the provided list
notInList: The value is not in the provided list
matches: The value matches the supplied regex pattern
isAnEmail: The value matches the StringValidationFunctions.emailRegExp pattern

Additional information #
The benefit of the chaining of functions allow user messages to be as customized
as possible.
For StringValidationFunctions errors are provided in line. This allows for
errors like in StringValidationFunctions.equals where it specifies the equal
value in the default error.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.