pvalidator 1.5.2 copy "pvalidator: ^1.5.2" to clipboard
pvalidator: ^1.5.2 copied to clipboard

A simple helper to validate inputs on flutter optimized for forms.

A simple package to validate inputs in flutter.

Sample PValidator

Features #

Avaliable rules

  • Accept values: list of accepted values
  • Date: test with DateTime.tryParse
  • Email: email validate
  • Max numeric: check max number
  • Max string: check max string size
  • Min numeric: check min number
  • Min string: check min string size
  • Numeric: check value is numeric
  • Regexp: validate with regular expression
  • Required: check if exist value
  • Requiredif: check if exist value if
  • Same: value must be same
  • Size string: value size check
  • Minimum date time: parse string and check is date is after the minimum
  • maximum date time: parse string and check is date is before the maximum
  • Size string: value size check
  • Integer: check value is a integer
  • Only one: check if only one value was entered

packages.yaml #

pvalidator: <lastest version>

Usage #

Mandatory field validation example:

TextFormField(
  validator: (string) {
    return PValidator([
      PRuleRequired(string),
    ]).val();
  },
)

PValidator is the master class. PRuleRequired is the validate rule. Set one or more rules to validate.

Validate with multiple rules:

TextFormField(
  validator: (string) {
    return PValidator([
      PRuleRequired(string),
      PRuleSizeString(string, 5),
    ]).val();
  },
)

Create your custom rule

import 'package:pvalidator/src/rules/rule.dart';

class MyCustomRule implements Rule {
  String? _value;
  String message;

  MyCustomRule(this._value, {this.message = "Value must be equal test"});

  @override
  String? validate() {
    if (_value == null || _value?.trim().length == 0) {
      return null;
    } else if (_value != "test") {
      return message;
    } else {
      return null;
    }
  }
}
1
likes
140
pub points
3%
popularity

Publisher

verified publisherpianta.dev

A simple helper to validate inputs on flutter optimized for forms.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on pvalidator