FormifyRule class abstract

An abstract class representing a validation rule for form field validation.

The FormifyRule class serves as a base class for creating custom validation rules to validate form field values.

Validation rules must implement the call method, which returns an error message if the validation fails or null if the validation succeeds.

Example usage:

class MyCustomRule extends FormifyRule {
  @override
  String? call(String attribute, String value) {
    // Implement your custom validation logic here.
    // Return an error message if validation fails, or `null` if it succeeds.
  }
}

The FormifyRule class provides several built-in static factory methods for common validation rules, such as required, numeric, integer, and more. You can also create custom validation rules by extending this class.

Available built-in validation rules:

  • required: Checks if the field value is not empty.
  • numeric: Checks if the field value is numeric (integer or decimal).
  • integer: Checks if the field value is an integer.
  • double: Checks if the field value is a decimal number.
  • between: Checks if the field value is within a specified numeric range.
  • min: Checks if the field value is greater than or equal to a minimum value.
  • max: Checks if the field value is less than or equal to a maximum value.
  • gt: Checks if the field value is greater than a specified value.
  • gte: Checks if the field value is greater than or equal to a specified value.
  • lt: Checks if the field value is less than a specified value.
  • lte: Checks if the field value is less than or equal to a specified value.
  • startsWith: Checks if the field value starts with a specified pattern.
  • endsWith: Checks if the field value ends with a specified pattern.
  • same: Checks if the field value is the same as a specified pattern.
  • lowercase: Checks if the field value is in lowercase.
  • uppercase: Checks if the field value is in uppercase.
  • alphaNumeric: Checks if the field value contains only letters and numbers.
  • email: Checks if the field value is a valid email address.
  • ip: Checks if the field value is a valid IP address.
  • url: Checks if the field value is a valid URL.
  • inItems: Checks if the field value is in a list of allowed items.
  • notInItems: Checks if the field value is not in a list of disallowed items.
  • regEx: Checks if the field value matches a specified regular expression pattern.

Custom validation rules can be created by extending this class and implementing the call method.

Implementers

Constructors

FormifyRule()
Creates an instance of the FormifyRule class with a generated unique key.
FormifyRule.withKey(String ruleKey)
Creates an instance of the FormifyRule class with a specified key.

Properties

hashCode int
The hash code for this object.
no setterinherited
message String
The error message template for validation failures.
getter/setter pair
ruleKey String
The unique key identifying the validation rule.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

buildMessage(String attribute, String input, {String onExtra(String)?}) String
Builds a validation error message by replacing placeholders in the error message template.
call(String attribute, String value) String?
Validates a field value and returns an error message if validation fails, or null if it succeeds.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

alphaNumeric FormifyRule
Static factory method to create a alphaNumeric validation rule.
no setter
double FormifyRule
Static factory method to create a double validation rule.
no setter
email FormifyRule
Static factory method to create a email validation rule.
no setter
integer FormifyRule
Static factory method to create an integer validation rule.
no setter
ip FormifyRule
Static factory method to create a ip validation rule.
no setter
lowercase FormifyRule
Static factory method to create a lowercase validation rule.
no setter
numeric FormifyRule
Static factory method to create a numeric validation rule.
no setter
required FormifyRule
Static factory method to create a required validation rule.
no setter
uppercase FormifyRule
Static factory method to create a uppercase validation rule.
no setter
url FormifyRule
Static factory method to create a url validation rule.
no setter

Static Methods

between(num min, num max) FormifyRule
Static factory method to create a between validation rule.
endsWith(String pattern) FormifyRule
Static factory method to create a endsWith validation rule.
gt(num number) FormifyRule
Static factory method to create a gt validation rule.
gte(num number) FormifyRule
Static factory method to create a gte validation rule.
inItems(List<String> items) FormifyRule
Static factory method to create a inItems validation rule.
lt(num number) FormifyRule
Static factory method to create a lt validation rule.
lte(num number) FormifyRule
Static factory method to create a lte validation rule.
max(num number) FormifyRule
Static factory method to create a max validation rule.
min(num number) FormifyRule
Static factory method to create a min validation rule.
notInItems(List<String> items) FormifyRule
Static factory method to create a notInItems validation rule.
regEx(String pattern) FormifyRule
Static factory method to create a regEx validation rule.
same(String pattern) FormifyRule
Static factory method to create a same validation rule.
startsWith(String pattern) FormifyRule
Static factory method to create a startsWith validation rule.