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

i_validator package provides a collection of common validation utilities such as email, password, phone number, OTP, and required fields validation. It also includes custom validation for confirm pass [...]

i_validator #

A Flutter package that provides various validation utilities for email, password, phone number, OTP, and required fields. It includes predefined regular expressions and validation classes to ensure proper input validation in Flutter applications.

Features #

  • Generic Validator Interface: IValidator<T> now supports any input type, improving reusability and type safety.
  • Email Validation: Checks if an email address is properly formatted.
  • Password Validation: Ensures passwords meet security requirements (e.g., uppercase, lowercase, number, special character, minimum length).
  • Confirm Password Validation: Verifies that the confirmation password matches the original password.
  • Phone Number Validation: Checks for valid phone number formats.
  • OTP Validation: Ensures OTP codes are of the correct length.
  • Required Field Validation: Ensures required fields are not left empty.
  • Min/Max Value Validation: Generic number range validators for numeric fields.
  • File Validation: Checks for valid image file formats.

Installation #

Add this to your pubspec.yaml:

dependencies:
  i_validator: latest_version

Then, run:

flutter pub get

Usage #

Import the package:

import 'package:i_validator/i_validator.dart';

Email Validation #

String? emailError = EmailValidator().validate("test@example.com");
if (emailError != null) {
  print(emailError); // "Enter valid Email"
}

Password Validation (Strong) #

String? passwordError = PasswordValidator(
  minLength: 8,
  strength: PasswordStrength.strong,
).validate("Test@123");
if (passwordError != null) {
  print(passwordError); // "Invalid Password"
}

Confirm Password Validation #

String? confirmPasswordError = ConfirmPasswordValidator(password:"Test@123")
    .validate("Test@123");
if (confirmPasswordError != null) {
  print(confirmPasswordError); // "Password doesn't match"
}

Phone Number Validation #

String? phoneError = PhoneNumberValidator().validate("01712345678");
if (phoneError != null) {
  print(phoneError); // "Invalid Phone Number"
}

OTP Validation (6-digit) #

String? otpError = OtpValidator(length: 6).validate("123456");
if (otpError != null) {
  print(otpError); // "Invalid OTP code"
}

Required Field Validation (Generic) #

String? requiredError = RequiredFieldValidator<String>().validate("");
if (requiredError != null) {
  print(requiredError); // "Required Field Can't Be Empty"
}

Min/Max Value Validation #

final minValidator = MinValueValidator<int>(min: 10);
print(minValidator.validate(5)); // "Value must be at least 10"

final maxValidator = MaxValueValidator<double>(max: 100.0);
print(maxValidator.validate(150.0)); // "Value must be at most 100.0"

License #

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

11
likes
0
points
129
downloads

Publisher

unverified uploader

Weekly Downloads

i_validator package provides a collection of common validation utilities such as email, password, phone number, OTP, and required fields validation. It also includes custom validation for confirm passwords and file formats, along with mixins for Stream-based validation.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on i_validator