Search packages, repositories and app categories

Package detailsv1.1.0

form_field_validator

A straightforward flutter form field validator that provides common validation options.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
32.8K
Likes
457
Pub points
140

Install package

flutter pub add form_field_validator

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A lightweight Flutter package that simplifies form validation by offering a set of common validation rules. It provides easy-to-use methods for checking inputs like required fields, email formats, passwords, and more. Designed to integrate seamlessly with Flutter's form widgets, it reduces boilerplate code while ensuring consistent validation across different form fields. The package is actively maintained and supports all major platforms including Android, iOS, Web, macOS, Windows, and Linux.

Use cases

  • Validating user registration forms
  • Checking email and password inputs
  • Ensuring required fields are filled
  • Implementing custom validation logic
  • Building responsive and dynamic forms

Key features

  • Predefined validation rules
  • Simple API integration
  • Supports multiple platforms
  • Extensible for custom validators
  • Clear error messages

Suitable for

  • Beginner Flutter developers
  • Projects requiring quick form validation
  • Apps with complex input forms
  • Teams prioritizing development speed
  • Cross-platform mobile and web apps

Considerations

  • Limited to basic validation out of the box
  • Custom logic may require additional implementation
  • Not ideal for highly complex validation workflows

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

form_field_validator

A straightforward flutter form field validator that provides common validation options.

Usage

     // assign it directly to a TextFormField validator  
     // you don't have the pass the value your self like  
     // validator: (value) => EmailValidator(errorText: 'invalid email address').call(value)  
       
     TextFormField(  
         validator: EmailValidator(errorText: 'enter a valid email address')  
         );  
   
     // create a reusable instance  
     final requiredValidator = RequiredValidator(errorText: 'this field is required');  
     
     // again assign it directly to the validator  
     TextFormField(validator: requiredValidator);  
     

Multi rules validation

   
  final passwordValidator = MultiValidator([  
    RequiredValidator(errorText: 'password is required'),  
    MinLengthValidator(8, errorText: 'password must be at least 8 digits long'),  
    PatternValidator(r'(?=.*?[#?!@$%^&*-])', errorText: '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 validator to the TextFormField validator  
        validator: passwordValidator,  
      ),  
  
      // using the match validator to confirm password  
      TextFormField(  
        validator: (val) => MatchValidator(errorText: 'passwords do not match').validateMatch(val, password),  
      )  
    ]),  
  );  
    

Make your own validator

   
class LYDPhoneValidator extends TextFieldValidator {  
  // pass the error text to the super constructor  
  LYDPhoneValidator({String errorText = 'enter a valid LYD phone number'}) : super(errorText);  
  
  // return false if you want the validator to return error  
  // message when the value is empty.  
  @override  
   bool get ignoreEmptyValues => true;  
    
	  @override  
	  bool isValid(String value) {  
	    // return true if the value is valid according the your condition  
	    return hasMatch(r'^((+|00)?218|0?)?(9[0-9]{8})$', value);  
	  }  
}  


   // use it by assigning it to the TextFormField validator  
   TextFormField(validator: LYDPhoneValidator());  


  
  
// you can also extend the base FieldValidator class   
// to work with non string values  
  
class CustomValidator extends FieldValidator<T>{  
   CustomValidator(String errorText) : super(errorText);  
  
	  @override  
	  bool isValid(T value) {  
	    // TODO: implement isValid  
	    return //condition;
	  }  
  }  
  

Categories

Dependencies

Dependency list 1 items

  • intl>=0.17.0 <=1.0.0

Source repository

Projects using this package