universal_validator 1.0.4 copy "universal_validator: ^1.0.4" to clipboard
universal_validator: ^1.0.4 copied to clipboard

The ultimate Flutter form validation library. Validators & smart widgets for Email, Phone, Password, Credit Card, UPI, and Indian docs (Aadhaar, PAN, GST, IFSC).

Universal Validator #

pub package popularity likes pub points

A comprehensive Flutter package providing reusable form validators, smart input widgets, and formatting utilities. Reduce boilerplate code and ensure consistent validation across your Flutter applications.

🚀 Why Universal Validator? #

  • 🔍 Pre-built Validators: Email, phone, password, name, PAN, GST, and more
  • 🎯 Smart Widgets: Input fields with built-in validation and formatting
  • 🌍 International Support: Phone numbers, email formats, and localization
  • Real-time Validation: Debounced validation with customizable timing
  • 🎨 Customizable: Custom error messages, validation rules, and formatting
  • 📱 Cross-platform: Works on iOS, Android, Web, and Desktop
  • 🧪 Well Tested: Comprehensive test coverage with property-based testing

📦 Installation #

Add this to your package's pubspec.yaml file:

dependencies:
  universal_validator: ^1.0.3

Then run:

flutter pub get

🚀 Quick Start #

Basic Validators #

import 'package:universal_validator/universal_validator.dart';

// Email validation
String? emailError = EmailValidator.validate('user@example.com');
print(emailError); // null (valid)

// Phone validation (supports international formats)
String? phoneError = PhoneValidator.validate('+919876543210');
print(phoneError); // null (valid)

// Password validation
String? passwordError = PasswordValidator.validate('MySecure123!');
print(passwordError); // null (valid)

Smart Text Fields #

import 'package:flutter/material.dart';
import 'package:universal_validator/universal_validator.dart';

class MyForm extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        // Email field with built-in validation
        SmartTextField(
          fieldType: FieldType.email,
          decoration: InputDecoration(
            labelText: 'Email',
            hintText: 'Enter your email',
          ),
          onValidationChanged: (result) {
            print('Email valid: ${result.isValid}');
          },
        ),
        
        // Phone field with formatting
        SmartTextField(
          fieldType: FieldType.phone,
          decoration: InputDecoration(
            labelText: 'Phone Number',
            hintText: 'Enter phone number',
          ),
          showSuccessIndicator: true,
        ),
        
        // Password field with strength validation
        SmartTextField(
          fieldType: FieldType.password,
          decoration: InputDecoration(
            labelText: 'Password',
            hintText: 'Enter a strong password',
          ),
          obscureText: true,
        ),
      ],
    );
  }
}

📋 Supported Validators #

🌐 General Validators #

Validator Description Example
Email RFC-compliant validation with domain check user@domain.com
Phone International & Indian phone formats +919876543210, 9876543210
Password Configurable strength (uppercase, special chars, etc.) MySecure123!
Name Names with cultural character support John Doe, Mary-Jane

💳 Finance & Payments #

Validator Description Example
Credit Card Luhn algorithm validation for major networks 4532 1234 5678 9012
Card Expiry Validates MM/YY format & future dates 12/26
Card CVC Validates 3-4 digit security codes 123, 4567
UPI ID Unified Payments Interface ID format user@upi, merchant@bank

🇮🇳 Indian Documents (KYC) #

Validator Description Example
Aadhaar 12-digit UID with Verhoeff algorithm check 1234 5678 9012
PAN Permanent Account Number (AAAAA9999A) ABCDE1234F
GST GSTIN validation with checksum 22AAAAA0000A1ZC
IFSC Indian Financial System Code for banks SBIN0001234
Vehicle Indian Vehicle Registration Number MH12AB1234

� Smart Widgets #

SmartTextField #

A powerful text field widget with built-in validation and formatting:

SmartTextField(
  fieldType: FieldType.email,
  enableRealTimeValidation: true,
  validationDebounce: Duration(milliseconds: 300),
  showSuccessIndicator: true,
  customErrorMessages: {
    'email': 'Please enter a valid email address',
  },
  onValidationChanged: (ValidationResult result) {
    // Handle validation state changes
    if (result.isValid) {
      print('Input is valid!');
    } else {
      print('Error: ${result.errorMessage}');
    }
  },
)

Properties #

Property Type Description Default
fieldType FieldType Type of field (email, phone, etc.) Required
controller TextEditingController? Controller for the text field null
enableRealTimeValidation bool Validate as user types true
validationDebounce Duration Delay before validating 300ms
showSuccessIndicator bool Show checkmark when valid false
customErrorMessages Map<String, String>? Override default errors null
onValidationChanged Function(ValidationResult)? Callback for validation state null
configuration FieldConfiguration? Advanced field config null

Field Types #

enum FieldType {
  email,         // Email addresses
  phone,         // Phone numbers (international/Indian)
  password,      // Passwords with strength validation
  name,          // Person names
  pan,           // Indian PAN cards
  gst,           // Indian GST numbers
  aadhaar,       // Indian Aadhaar numbers
  ifsc,          // Indian Financial System Code
  upi,           // UPI IDs
  vehicleNumber, // Indian Vehicle Registration Numbers
  cardNumber,    // Credit/Debit card numbers
  cardExpiry,    // Card expiry dates
  cardCVC,       // Card security codes
  custom,        // Custom validation rules
}

⚙️ Advanced Configuration #

Custom Password Validation #

final passwordConfig = PasswordConfig(
  minLength: 12,
  requireUppercase: true,
  requireLowercase: true,
  requireNumbers: true,
  requireSpecialChars: true,
  forbiddenPasswords: ['password123', 'admin'],
);

SmartTextField(
  fieldType: FieldType.password,
  configuration: FieldConfiguration(
    parameters: {'passwordConfig': passwordConfig},
  ),
)

Custom Validation Rules #

SmartTextField(
  fieldType: FieldType.custom,
  configuration: FieldConfiguration(
    customRules: [
      ValidationRule(
        name: 'minLength',
        validator: (value) => value?.length >= 5,
        errorMessage: 'Must be at least 5 characters',
        priority: 1,
      ),
      ValidationRule(
        name: 'noSpaces',
        validator: (value) => !value?.contains(' ') ?? true,
        errorMessage: 'Spaces are not allowed',
        priority: 2,
      ),
    ],
  ),
)

Input Formatting #

// Phone number formatting
String formatted = PhoneFormatter.format('9876543210');
print(formatted); // "98765 43210"

// Name formatting (title case)
String formattedName = NameFormatter.format('john doe');
print(formattedName); // "John Doe"

// PAN formatting (uppercase)
String formattedPAN = PANFormatter.format('abcde1234f');
print(formattedPAN); // "ABCDE1234F"

🌍 Internationalization #

Phone Number Support #

// Indian numbers
PhoneValidator.validate('9876543210'); // ✅ Valid
PhoneValidator.validate('+919876543210'); // ✅ Valid

// US numbers
PhoneValidator.validate('+12345678901'); // ✅ Valid

// UK numbers
PhoneValidator.validate('+441234567890'); // ✅ Valid

Custom Error Messages #

SmartTextField(
  fieldType: FieldType.email,
  customErrorMessages: {
    'email': 'कृपया एक वैध ईमेल पता दर्ज करें', // Hindi
    'required': 'यह फ़ील्ड आवश्यक है',
  },
)

🧪 Testing #

The package includes comprehensive property-based tests to ensure reliability:

# Run all tests
flutter test

# Run specific validator tests
flutter test test/email_validator_property_test.dart
flutter test test/phone_validator_property_test.dart

📱 Platform Support #

Platform Support
Android
iOS
Web
macOS
Windows
Linux

🤝 Contributing #

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Development Setup #

  1. Fork the repository
  2. Clone your fork: git clone https://github.com/your-username/universal_validator.git
  3. Create a feature branch: git checkout -b feature/amazing-feature
  4. Make your changes and add tests
  5. Run tests: flutter test
  6. Commit your changes: git commit -m 'Add amazing feature'
  7. Push to the branch: git push origin feature/amazing-feature
  8. Open a Pull Request

📄 License #

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

🙏 Acknowledgments #

  • Thanks to all contributors who have helped improve this package
  • Inspired by the need for consistent form validation in Flutter applications
  • Built with ❤️ for the Flutter community

📞 Support #


Made with ❤️ by Dhairya Soni

1
likes
160
points
265
downloads

Publisher

unverified uploader

Weekly Downloads

The ultimate Flutter form validation library. Validators & smart widgets for Email, Phone, Password, Credit Card, UPI, and Indian docs (Aadhaar, PAN, GST, IFSC).

Repository (GitHub)
View/report issues

Topics

#validation #form #widget #validators #flutter

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on universal_validator