enterprise_validator 0.0.5 copy "enterprise_validator: ^0.0.5" to clipboard
enterprise_validator: ^0.0.5 copied to clipboard

A package which have built in injectable validations, and enables you to create your own.

example/README.md

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);

Inject Multiple Validation Rules #

   
  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),  
      )  
    ]),  
  );  
    

Make your own validation rule #

   
 class Is[YourRuleName]Rule extends ValidationRule {
  Is[YourRuleName]Rule({required String validationError}) : super(validationError: validationError);

  @override
  bool check(String? value) {
    // Apply here your custom validation rule
    // then return true/ false based on your logic.
    return true/false;
  }
}
    
2
likes
110
pub points
50%
popularity

Publisher

unverified uploader

A package which have built in injectable validations, and enables you to create your own.

Repository (GitHub)
View/report issues

Documentation

API reference

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on enterprise_validator