enterprise_validator

Last updated:

0 purchases

enterprise_validator Image
enterprise_validator Images
Add to Cart

Description:

enterprise validator

This package aims to simplify the process of injecting validation rules, to your form fields, taking the single responsibility from SOLID Design pattern,
Each class of validation represents a validation rule, which can be applied to your inputs.
also you can implement your own validation rules.
Features #

Provide about 16 built-in validations

Strings

Validating email
Validating json
Validating required
Validating length (Min, Max, Exact)
Validating Mobile Phones (Egyptian, Saudi)
Validating Regex Pattern
Validating Guid


Numbers

Validating Equal to
Validating Not Equal to
Validating Not Equal to Zero
Validating Range Of





Getting started #
import 'package:enterprise_validator/enterprise_validator.dart';
copied to clipboard
Usage #
Inject Single Validation Rule #

// assign it directly to a TextFormField validator
TextFormField(
validator: IsEmailAddressRule(validationError: 'enter a valid email address')
);

// create a reusable instance
final requiredValidation = IsEmailAddressRule(validationError :'this field is required');

// again assign it directly to the validator
TextFormField(validator: requiredValidation);
copied to clipboard
Inject Multiple Validation Rules #
// Orders of validation matters, the first rule you add, the first validation fires.

final passwordRules = MultiValidationRules([
IsRequiredRule(validationError: 'password is required'),
IsMinimumLengthRule(8, validationError: 'password must be at least 8 digits long'),
IsValidPatternRule(r'(?=.*?[#?!@$%^&*-])', validationError: 'passwords must have at least one special character')
]);

String password;

Form(
key: _formKey,
child: Column(children: [
TextFormField(
obscureText: true,
onChanged: (val) => password = val,
// assign the the multi validation rules to the TextFormField validator
validator: passwordRules,
),

// using the match validator to confirm password
TextFormField(
validator: (val) => MatchRule(validationError: 'passwords do not match').validateMatch(val, password),
)
]),
);

copied to clipboard
Additional information #

This package is still in its initial stage, which means, it may have break changes.
This package is a personal attempt to make the process of validation easier, it is open source, you can get the code and add your own custom logic.
It's open to contribute and contact with me for any future improvements for the package.

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.