king_validation 1.2.0
king_validation: ^1.2.0 copied to clipboard
A lightweight Flutter and Dart validation package with standalone validators, Form Validators, custom validation messages, and RegExp-based validation.
๐ King Validation #
A lightweight, fast, and easy-to-use Flutter/Dart validation package for validating user input.
Supports both:
- โ Standalone Validators
- โ Flutter Form Validators
- โ Custom Validation Messages
- โ Custom Regular Expressions
- โ Null Safety
โจ Features #
- ๐ง Email Validation
- ๐ Password Validation
- ๐ฑ Phone Validation
- ๐ค Username Validation
- ๐ Name Validation
- ๐ URL Validation
- ๐ฆ Empty Validation
- ๐ข Number Validation
- ๐ OTP Validation
- ๐ณ Credit Card Validation
- ๐ ๏ธ Custom Validation
- ๐ Flutter Form Validators
- ๐จ Custom Validation Messages
๐ Installation #
Add the package to your pubspec.yaml.
dependencies:
king_validation: ^1.2.0
Install packages:
flutter pub get
๐ฅ Import #
import 'package:king_validation/king_validation.dart';
๐ Quick Start #
Standalone Validator #
final result = EmailValidator.validate(
'hero@gmail.com',
);
if (result.isValid) {
print('Valid Email');
} else {
print(result.error);
}
Flutter Form Validator #
TextFormField(
decoration: const InputDecoration(
labelText: 'Email',
),
validator: const EmailFormValidator().call,
)
Custom Validation Messages #
TextFormField(
decoration: const InputDecoration(
labelText: 'Email',
),
validator: const EmailFormValidator(
messages: {
ValidationError.empty:
'Email is required.',
ValidationError.invalidEmail:
'Please enter a valid email.',
},
).call,
)
Every
FormValidatorsupports custom validation messages through themessagesparameter.
Custom Regular Expression #
TextFormField(
validator: CustomFormValidator(
pattern: RegExp(r'^[A-Z0-9]+$'),
).call,
)
๐ Validation Result #
Every standalone validator returns a ValidationResult.
final result = EmailValidator.validate(
'hero@gmail.com',
);
print(result.isValid);
print(result.error);
๐ More Validator Examples #
Password #
PasswordValidator.validate('Hero@123');
Phone #
PhoneValidator.validate('+1234567890');
Username #
UsernameValidator.validate('hero_123');
Name #
NameValidator.validate('Hero Ahmed');
URL #
UrlValidator.validate('https://flutter.dev');
Empty #
EmptyValidator.validate('');
Number #
NumberValidator.validate('12345');
OTP #
OtpValidator.validate('123456');
Credit Card #
CreditCardValidator.validate('4111111111111111');
๐ Available Validators #
Standalone Validators #
| Validator | Description |
|---|---|
| EmailValidator | Validate email addresses |
| PasswordValidator | Validate passwords |
| PhoneValidator | Validate phone numbers |
| UsernameValidator | Validate usernames |
| NameValidator | Validate names |
| UrlValidator | Validate URLs |
| EmptyValidator | Validate empty values |
| NumberValidator | Validate numeric values |
| OtpValidator | Validate OTP codes |
| CreditCardValidator | Validate credit card numbers |
| CustomValidator | Validate custom regular expressions |
Flutter Form Validators #
| Form Validator |
|---|
| EmailFormValidator |
| PasswordFormValidator |
| PhoneFormValidator |
| UsernameFormValidator |
| NameFormValidator |
| UrlFormValidator |
| EmptyFormValidator |
| NumberFormValidator |
| OtpFormValidator |
| CreditCardFormValidator |
| CustomFormValidator |
All Form Validators expose the same API and can be used directly with TextFormField.validator.
๐ Example #
A complete Flutter example is available in the example/ directory.
The example application demonstrates:
- โ Standalone Validators
- โ Flutter Form Validators
- โ Default Validation Messages
- โ Custom Validation Messages
- โ Custom Regular Expressions
- โ Material 3 UI
๐งช Quality #
- โ 104 Unit Tests
- โ Flutter Example Included
- โ Null Safety
- โ Flutter Support
- โ Dart Support
๐ค Contributing #
Contributions, issues, and feature requests are welcome.
๐ License #
MIT License
Made with โค๏ธ using Flutter & Dart.