validator_forge 2.2.0 copy "validator_forge: ^2.2.0" to clipboard
validator_forge: ^2.2.0 copied to clipboard

A robust and easy-to-use Flutter form validation package. Provides pre-built validators, custom regex, and a flexible builder for intuitive form handling.

🛡️ Validator Forge #

Pub Version Flutter Platform Build Status License: MIT

A robust, elegant, and easy-to-use form validation package for Flutter.

Tired of messy Validator functions cluttering your UI code? Validator Forge provides intuitive pre-built validators, custom regex support, and a highly flexible ValidationBuilder to chain rules beautifully directly in your UI.


✨ Features #

  • ⛓️ ValidationBuilder: Chain multiple validation rules effortlessly.
  • 📦 Pre-built rules: Email, passwords, URL, phone numbers, min/max limits, etc.
  • 🧑‍💻 Regex support: Need a custom pattern? We got you.
  • 🌍 Fully localizable: Customize every single error message to match your app's language.
  • Lightweight: Zero external dependencies, pure Dart.

🚀 Getting Started #

Add the dependency to your pubspec.yaml:

dependencies:
  validator_forge: ^2.1.0

Run flutter pub get after adding the dependency.


💻 Usage #

Import the package in your Dart file:

import 'package:validator_forge/validator_forge.dart';

The Elegant Way (Using ValidationBuilder) #

The absolute cleanest way to write your validators. It returns the first validation error it encounters.

TextFormField(
  decoration: InputDecoration(labelText: 'Email Address'),
  validator: ValidationBuilder()
      .required('Email is required')
      .email('Please enter a valid email address')
      .maxLength(50, 'Max length is 50 characters')
      .build,
),

The Direct Way (Using Static Methods) #

If you just need a quick, one-off validation without the builder:

TextFormField(
  decoration: InputDecoration(labelText: 'Phone Number'),
  validator: (value) => Validators.phone(
    value, 
    errorMessage: 'Must be a valid 10-digit number',
  ),
),

Validating custom matching (e.g. Confirm Password) #

TextFormField(
  decoration: InputDecoration(labelText: 'Confirm Password'),
  validator: (value) => Validators.match(
    value, 
    _passwordController.text, 
    errorMessage: 'Passwords do not match!',
  ),
),

🧰 Available Validators #

Here is a full list of rules you can enforce using the ValidationBuilder or the Validators static methods:

Validator Description Example Builder Usage
required Ensures field is not empty .required('Cannot be empty')
email Checks for valid email .email('Invalid email')
phone Checks for 10-digit phone number .phone('Invalid phone')
password Ensures min 8 characters .password('Password too short')
url Verifies URL format .url('Broken link')
minLength Checks minimum characters .minLength(5, 'Too short')
maxLength Checks maximum characters .maxLength(10, 'Too long')
number Ensures input is a number .number('Must be a number')
minimum Minimum numeric value Validators.minimum(10, 50)
maximum Maximum numeric value Validators.maximum(10, 50)
date Matches YYYY-MM-DD .date('Invalid date')
customDate Custom localized Date regex format .customDate(ValidDateFormats.ddMmYyyySlash, 'Invalid')
match Matches another value exactly Validators.match(val, val2)
matchRegex Matches a custom Regex Pattern .matchRegex(r'^abc', 'Must start with abc')
rule Custom boolean condition rule .rule((v) => v == 'admin', 'Error')
creditCard Validates standard credit card format .creditCard('Invalid card')
ipv4 Validates an IPv4 address .ipv4('Invalid IP')
ipv6 Validates an IPv6 address .ipv6('Invalid IP')
strongPassword Enforces strong password criteria .strongPassword('Too weak')
hexColor Validates a hex color code .hexColor('Invalid hex')

📱 Check out the Example #

Curious to see it in action? Look at the example tab for a comprehensive, beautiful UI demonstration, or run the app locally!


🤝 Contributing #

Contributions are always welcome! Feel free to open an issue or submit a pull request on our GitHub repository.

📄 License #

This project is licensed under the MIT License - see the LICENSE file for details.

7
likes
155
points
121
downloads

Documentation

API reference

Publisher

verified publisherhiteshpatel.tech

Weekly Downloads

A robust and easy-to-use Flutter form validation package. Provides pre-built validators, custom regex, and a flexible builder for intuitive form handling.

Repository (GitHub)
View/report issues

Topics

#flutter #form #validator #validation #regex

License

MIT (license)

Dependencies

flutter

More

Packages that depend on validator_forge