x_validators 1.0.3 copy "x_validators: ^1.0.3" to clipboard
x_validators: ^1.0.3 copied to clipboard

X Validators is a library that simplifies data validation in your applications.

☕ X Validators #

Pub GitHub License

Simplest form validation for flutter form widgets.

  • Zero dependency
  • Extensible
  • Well tested
  • Open source

🚀 Installation #

Add the following to your pubspec.yaml file

dependencies:
   x_validators: ^1.0.3

Don't forget to flutter pub get.

Api Overview #

Rules for Text Description
IsRequired() Ensures that the trimmed input is not empty.
Contains() Verifies if the input string contains the provided value.
EndsWith() Ensures that the input string ends with a specific value.
IsEmpty() Ensures that the trimmed input is empty.
Match() Verifies if the input matches the specified string.
MaxLength() Ensures that the length is less than or equal to the specified maximum.
MinLength() Ensures that the length is greater than or equal to the specified minimum.
NotContains() Verifies if the input string does not contain the provided value.
StartsWith() Ensures that the input string starts with a specific pattern.
Rules for NUMBERS Description
IsArabicNum() Verifies if the input is a valid Arabic integer.
IsHindiNum() Verifies if the input is a valid Hindi integer.
IsNumber() Verifies if the input is a valid integer.
MaxValue() Verifies if the numeric value is less than or equal to the specified maximum.
MinValue() Verifies if the numeric value is greater than or equal to the specified minimum.
Rules for URLS Description
IsFacebookUrl() Verifies if the input is a valid Facebook URL.
IsInstagramUrl() Verifies if the input is a valid Instagram URL.
IsSecureUrl() Verifies if the input is a secure URL (starts with 'https://').
IsUrl() Verifies if the input is a valid URL.
IsYoutubeUrl() Verifies if the input is a valid YouTube URL.
Rules for Phone Description
IsEgyptianPhone() Verifies if the input is a valid Egyptian phone number.
ISKsaPhone() Verifies if the input is a valid Saudi Arabian phone number.

How to Use #

📚Basic use

Demonstrates basic usage of IsRequired validation rule to ensure that the input is not empty.
  TextFormField(
                decoration: const InputDecoration(labelText: 'IsRequired'),
                validator: xValidator([
                 
                  IsRequired(),
                ]),
              ),

📚onFailureCallBack

Illustrates more complex validation with multiple rules (IsRequired, MinLength, MaxLength).
The onFailureCallBack is triggered for any rule failure, logging the input and the failed rule for analysis.
TextFormField(
  decoration: const InputDecoration(labelText: 'IsRequired'),
  validator: xValidator([
    // Ensures that the input is not empty with a custom error message.
    IsRequired("Field cannot be empty"),

    // Ensures that the input has a minimum length of 3 characters.
    MinLength(3, "Field must be at least 3 characters"),

    // Ensures that the input does not exceed a maximum length of 20 characters.
    MaxLength(20, "Field cannot exceed 20 characters"),
  ], onFailureCallBack: (String? input, List<TextXValidationRule> rules, TextXValidationRule failedRule) {
    // Logs information about the failed validation for further analysis.
    log("###### Validation failed for input #### : $input");
    log("#### Failed rule #### : $failedRule");
  }),
),
Explanation:

The first example demonstrates basic usage of IsRequired validation rule. It ensures that the input is not empty. The second example uses multiple rules (IsRequired, MinLength, MaxLength) for more complex validation. It also includes an onFailureCallBack to handle validation failures. If any rule fails, the callback is triggered, logging the input and the failed rule for further analysis.

License #

Please see LICENSE.

👨🏻‍💻 Authors #

9
likes
0
points
79
downloads

Publisher

unverified uploader

Weekly Downloads

X Validators is a library that simplifies data validation in your applications.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on x_validators