form_validators_plus 1.0.0 copy "form_validators_plus: ^1.0.0" to clipboard
form_validators_plus: ^1.0.0 copied to clipboard

A flexible Flutter and Dart validation library with ready-to-use rules and utilities

Flutter Form Validators #

pub package License: MIT

A comprehensive, production-ready form validation library for Flutter with 20+ validators, security features, and 40+ string extensions.

โœจ Features #

  • ๐ŸŽฏ 20+ Built-in Validators - Email, phone, credit card, password strength, URL, and more
  • ๐Ÿ”— Chainable API - Combine multiple validators effortlessly
  • ๐Ÿ›ก๏ธ Security First - XSS and SQL injection prevention
  • ๐Ÿ’ณ Advanced Credit Card - Luhn algorithm with automatic type detection
  • ๐ŸŒ Internationalization - Multi-language error messages
  • ๐Ÿš€ 40+ String Extensions - Quick validation checks
  • โœ… 100% Test Coverage - Production-ready reliability

๐Ÿš€ Installation #

Add to your pubspec.yaml:

dependencies:
  flutter_form_validators: ^1.0.0

Then run:

flutter pub get

๐Ÿ“– Usage #

Basic Example #

import 'package:flutter_form_validators/flutter_form_validators.dart';

TextFormField(
  validator: Validators.email(),
  decoration: InputDecoration(labelText: 'Email'),
)

Combining Validators #

TextFormField(
  validator: Validators.combine([
    Validators.required(),
    Validators.email(),
    Validators.minLength(5),
  ]),
)

String Extensions #

if ('test@example.com'.isValidEmail) {
  print('Valid email!');
}

if ('Password123!'.isStrongPassword) {
  print('Strong password!');
}

final score = 'MyPass123!'.passwordStrengthScore; // 0-5

Available Validators #

Core Validators

  • required() - Field must not be empty
  • email() - Valid email format
  • minLength(int) / maxLength(int) - Length constraints
  • numeric() - Numbers only
  • url() - Valid URL format

Advanced Validators

  • password() - Password strength with customizable requirements
  • phoneNumber() - Phone validation (US, UK, International)
  • creditCard() - Credit card with Luhn algorithm & type detection
  • match(String) - Field matching (password confirmation)
  • username() - Username format validation
  • date() - Date format validation
  • range(min, max) - Numeric range validation

Security & Geographic

  • secure() - XSS and injection prevention
  • postalCode() - ZIP codes (US, Canada, UK)
  • ssn() - Social Security Numbers
  • ipAddress() - IPv4 and IPv6
  • macAddress() - MAC address validation

Password Validation Example #

TextFormField(
  validator: Validators.password(
    minLength: 12,
    requireUppercase: true,
    requireLowercase: true,
    requireNumbers: true,
    requireSpecialChars: true,
  ),
)

Credit Card Example #

TextFormField(
  validator: Validators.creditCard(
    acceptedTypes: [CreditCardType.visa, CreditCardType.mastercard],
  ),
)

// Or use extensions
if ('4532015112830366'.isValidCreditCard) {
  final type = '4532015112830366'.creditCardType; // CreditCardType.visa
}

๐Ÿ”ฅ String Extensions #

// Validation
'test@email.com'.isValidEmail // true
'https://example.com'.isValidUrl // true
'123'.isNumeric // true

// Password Analysis  
'Password123!'.isStrongPassword // true
'Password123!'.passwordStrengthScore // 5 (out of 5)
'Password123!'.passwordStrengthLevel // 'Very Strong'

// Credit Cards
'4532015112830366'.isValidCreditCard // true
'4532015112830366'.creditCardType // CreditCardType.visa

// Text Manipulation
'hello world'.titleCase // 'Hello World'
'sensitive data'.masked(2) // 'se**********ta'
'long text here'.truncate(10) // 'long te...'

// Conversions
'123'.intValue // 123
'123.45'.numericValue // 123.45
'2024-01-01'.dateValue // DateTime object

๐Ÿ“ฑ Complete Example #

class RegistrationForm extends StatelessWidget {
  final _formKey = GlobalKey<FormState>();
  final _passwordController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Form(
      key: _formKey,
      child: Column(
        children: [
          TextFormField(
            validator: Validators.combine([
              Validators.required(),
              Validators.email(),
            ]),
            decoration: InputDecoration(labelText: 'Email'),
          ),
          TextFormField(
            controller: _passwordController,
            validator: Validators.password(),
            decoration: InputDecoration(labelText: 'Password'),
          ),
          TextFormField(
            validator: Validators.match(_passwordController.text),
            decoration: InputDecoration(labelText: 'Confirm Password'),
          ),
          ElevatedButton(
            onPressed: () {
              if (_formKey.currentState!.validate()) {
                // Form is valid
              }
            },
            child: Text('Submit'),
          ),
        ],
      ),
    );
  }
}

๐Ÿงช Testing #

Run tests:

flutter test

๐Ÿ“ธ Screenshots #

Registration Form #

Registration Form

Credit Card Validator #

Credit Card

Password Strength Analyzer #

Password Strength

String extensions #

Password Strength

๐Ÿค Contributing #

Contributions are welcome! Please feel free to submit a Pull Request.

๐Ÿ“ License #

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

๐Ÿ™ Support #

If you find this package helpful, please โญ star the repo and share it with other Flutter developers!


Made with โค๏ธ for the Flutter community

2
likes
160
points
35
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A flexible Flutter and Dart validation library with ready-to-use rules and utilities

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter

More

Packages that depend on form_validators_plus